Clean up specs: test only one thing, and refrain from using should in titles (better spec-doc).

This commit is contained in:
nathanvda 2012-03-12 23:53:52 +01:00
parent dece4624fb
commit d76104f083

View File

@ -19,12 +19,12 @@ describe Cocoon do
end end
context "without a block" do context "without a block" do
it "should accept a name" do it "accepts a name" do
result = @tester.link_to_add_association('add something', @form_obj, :comments) result = @tester.link_to_add_association('add something', @form_obj, :comments)
result.to_s.should == '<a href="#" class="add_fields" data-association="comment" data-associations="comments" data-template="form&lt;tag&gt;">add something</a>' result.to_s.should == '<a href="#" class="add_fields" data-association="comment" data-associations="comments" data-template="form&lt;tag&gt;">add something</a>'
end end
it "should accept html options and pass them to link_to" do it "accepts html options and pass them to link_to" do
result = @tester.link_to_add_association('add something', @form_obj, :comments, {:class => 'something silly'}) result = @tester.link_to_add_association('add something', @form_obj, :comments, {:class => 'something silly'})
result.to_s.should == '<a href="#" class="something silly add_fields" data-association="comment" data-associations="comments" data-template="form&lt;tag&gt;">add something</a>' result.to_s.should == '<a href="#" class="something silly add_fields" data-association="comment" data-associations="comments" data-template="form&lt;tag&gt;">add something</a>'
end end
@ -38,7 +38,7 @@ describe Cocoon do
result.to_s.should == '<a href="#" class="add_fields" data-association="comment" data-associations="comments" data-template="form&lt;tag&gt;">some long name</a>' result.to_s.should == '<a href="#" class="add_fields" data-association="comment" data-associations="comments" data-template="form&lt;tag&gt;">some long name</a>'
end end
it "should accept html options and pass them to link_to" do it "accepts html options and pass them to link_to" do
result = @tester.link_to_add_association(@form_obj, :comments, {:class => 'floppy disk'}) do result = @tester.link_to_add_association(@form_obj, :comments, {:class => 'floppy disk'}) do
"some long name" "some long name"
end end
@ -48,7 +48,7 @@ describe Cocoon do
end end
context "with an irregular plural" do context "with an irregular plural" do
it "should use the correct plural" do it "uses the correct plural" do
result = @tester.link_to_add_association('add something', @form_obj, :people) result = @tester.link_to_add_association('add something', @form_obj, :people)
result.to_s.should == '<a href="#" class="add_fields" data-association="person" data-associations="people" data-template="form&lt;tag&gt;">add something</a>' result.to_s.should == '<a href="#" class="add_fields" data-association="person" data-associations="people" data-template="form&lt;tag&gt;">add something</a>'
end end
@ -59,7 +59,7 @@ describe Cocoon do
end end
context "with extra render-options for rendering the child relation" do context "with extra render-options for rendering the child relation" do
it "should use the correct plural" do it "uses the correct plural" do
@tester.should_receive(:render_association).with(:people, @form_obj, anything, {:wrapper => 'inline'}, nil) @tester.should_receive(:render_association).with(:people, @form_obj, anything, {:wrapper => 'inline'}, nil)
result = @tester.link_to_add_association('add something', @form_obj, :people, :render_options => {:wrapper => 'inline'}) result = @tester.link_to_add_association('add something', @form_obj, :people, :render_options => {:wrapper => 'inline'})
result.to_s.should == '<a href="#" class="add_fields" data-association="person" data-associations="people" data-template="form&lt;tag&gt;">add something</a>' result.to_s.should == '<a href="#" class="add_fields" data-association="person" data-associations="people" data-template="form&lt;tag&gt;">add something</a>'
@ -105,13 +105,13 @@ describe Cocoon do
@form_obj = stub(:object => @post, :object_name => @post.class.name) @form_obj = stub(:object => @post, :object_name => @post.class.name)
end end
context "without a block" do context "without a block" do
it "should accept a name" do it "accepts a name" do
result = @tester.link_to_remove_association('remove something', @form_obj) result = @tester.link_to_remove_association('remove something', @form_obj)
result.to_s.should == "<input id=\"Post__destroy\" name=\"Post[_destroy]\" type=\"hidden\" /><a href=\"#\" class=\"remove_fields dynamic\">remove something</a>" result.to_s.should == "<input id=\"Post__destroy\" name=\"Post[_destroy]\" type=\"hidden\" /><a href=\"#\" class=\"remove_fields dynamic\">remove something</a>"
end end
it "should accept html options and pass them to link_to" do it "accepts html options and pass them to link_to" do
result = @tester.link_to_remove_association('remove something', @form_obj, {:class => 'add_some_class', :'data-something' => 'bla'}) result = @tester.link_to_remove_association('remove something', @form_obj, {:class => 'add_some_class', :'data-something' => 'bla'})
result.to_s.should == "<input id=\"Post__destroy\" name=\"Post[_destroy]\" type=\"hidden\" /><a href=\"#\" class=\"add_some_class remove_fields dynamic\" data-something=\"bla\">remove something</a>" result.to_s.should == "<input id=\"Post__destroy\" name=\"Post[_destroy]\" type=\"hidden\" /><a href=\"#\" class=\"add_some_class remove_fields dynamic\" data-something=\"bla\">remove something</a>"
end end
@ -126,7 +126,7 @@ describe Cocoon do
result.to_s.should == "<input id=\"Post__destroy\" name=\"Post[_destroy]\" type=\"hidden\" /><a href=\"#\" class=\"remove_fields dynamic\">remove some long name</a>" result.to_s.should == "<input id=\"Post__destroy\" name=\"Post[_destroy]\" type=\"hidden\" /><a href=\"#\" class=\"remove_fields dynamic\">remove some long name</a>"
end end
it "should accept html options and pass them to link_to" do it "accepts html options and pass them to link_to" do
result = @tester.link_to_remove_association(@form_obj, {:class => 'add_some_class', :'data-something' => 'bla'}) do result = @tester.link_to_remove_association(@form_obj, {:class => 'add_some_class', :'data-something' => 'bla'}) do
"remove some long name" "remove some long name"
end end
@ -141,10 +141,12 @@ describe Cocoon do
end end
end end
context "should create proper partial" do context "setup_partial" do
it "should create correct association" do it "generates the default partial name if no partial given" do
result = @tester.setup_partial(nil, :admin_comments) result = @tester.setup_partial(nil, :admin_comments)
result.should == "admin_comment_fields" result.should == "admin_comment_fields"
end
it "uses the given partial name" do
result = @tester.setup_partial("comment_fields", :admin_comments) result = @tester.setup_partial("comment_fields", :admin_comments)
result.should == "comment_fields" result.should == "comment_fields"
end end