[rspec-devel] [ rspec-Feature Requests-10262 ] Better Helper testing of Erb evaluation block helpers
noreply at rubyforge.org
noreply at rubyforge.org
Fri Apr 20 14:37:33 EDT 2007
Feature Requests item #10262, was opened at 2007-04-20 18:12
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=10262&group_id=797
Category: rails plugin
Group: None
>Status: Open
Priority: 3
Submitted By: Simon Nicholls (simon_nicholls)
Assigned to: David Chelimsky (dchelimsky)
Summary: Better Helper testing of Erb evaluation block helpers
Initial Comment:
I'd like to easily test helpers which in views would be called like this:
<% helper_method "foo" do %>
bar
<% end %>
Erb eval blocks instead of Erb output blocks.
Including ActionView::Helpers::TextHelper in HelperBehaviourHelpers would help if you can add that, as it's generally useful.
I can then do something like this in the spec:
describe ApplicationHelper, "testing Erb eval helper" do
before do
@result = ERB.new("<% helper_method 'foo' do %>bar<% end %>").result(binding)
end
it "should work anyway but could be nicer" do
@result.should == "foo..bar"
end
end
Works well enough, but can you think of a nicer way?
I also tried a more direct, method calling style, but it needs explicit concat usage in the block:
_erbout = ''
panel('foo') { concat("bar", binding) }
@result = _erbout
Well, it works, but the block fudging and sneaky _erbout use is a bit naff
----------------------------------------------------------------------
>Comment By: Simon Nicholls (simon_nicholls)
Date: 2007-04-20 20:37
Message:
That's great, thanks! Nice to know I'll be partaking of the
erb shortly.
BTW, I've been trying to get basic support for RSpec into
the Netbeans Ruby support:
http://wiki.netbeans.org/wiki/view/Ruby
Tor has been doing some great work, it's pretty much there.
----------------------------------------------------------------------
Comment By: David Chelimsky (dchelimsky)
Date: 2007-04-20 20:34
Message:
committed to trunk rev 1787.
thanks for the suggestion
----------------------------------------------------------------------
Comment By: David Chelimsky (dchelimsky)
Date: 2007-04-20 20:28
Message:
Cool. I've got this working but can't commit right now - will shortly.
----------------------------------------------------------------------
Comment By: Simon Nicholls (simon_nicholls)
Date: 2007-04-20 20:07
Message:
Hehe!
That's actually pretty nice when factored out!
----------------------------------------------------------------------
Comment By: David Chelimsky (dchelimsky)
Date: 2007-04-20 19:13
Message:
How about something like:
describe ApplicationHelper, "testing Erb eval helper" do
before do
@result = eval_erb("<% helper_method 'foo' do %>bar<% end %>")
end
it "should work anyway but could be nicer" do
@result.should == "foo..bar"
end
end
#eval_erb would basically wrap your original suggestion:
def eval_erb(text)
ERB.new(text).result(binding)
end
The nice thing about this is that it not only serves your rails app, but you could use it like this:
eval_erb("Columbian").should == "really good s**t"
:)
----------------------------------------------------------------------
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=10262&group_id=797
More information about the rspec-devel
mailing list