Skip to content

Instantly share code, notes, and snippets.

@andrewpthorp
Forked from benmanns/gist:1267915
Created October 6, 2011 16:53
Show Gist options
  • Save andrewpthorp/1267926 to your computer and use it in GitHub Desktop.
Save andrewpthorp/1267926 to your computer and use it in GitHub Desktop.
Preference for helper specs?
# Option 1:
# Use content to separate the helper from the spec
it "should have something" do
content = helper.some_helper_method
content.should have_tag('a', :text => 'foo')
end
# Option 2:
# Combine helper call and spec
it "should have something" do
helper.some_helper_method.should have_tag('a', :text => 'bar')
end
# Option 3:
# Use subject
context '#some_helper_method' do
before :each do
@params = 'foo'
end
subject { helper.some_helper_method(@params) }
it { should have_tag 'a', :text => 'bar' }
end
# If you use subject, do you save much when you get something like this:
describe '#some_helper_method' do
[
{ :filter => 'a', :text => 'A' },
{ :filter => 'b', :text => 'B' },
{ :filter => 'c', :text => 'C' }
].each do |p|
context "with a filter of #{p[:filter]}" do
it "should have the text #{p[:text]}" do
content = helper.some_helper_method(p[:filter])
content.should have_tag('a', :text => p[:text])
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment