Thanks for tips sharing!
]]>You can use a combination of subject
and its
for the output to make more sense.
subject { @obj } its(:field1) { should == 37 } its(:filed2) { should == 19 }
Also, if your object is an ActiveRecord model, you could use set
which is available as a gem.
Cheers
]]>I still have one thorny problem, though. Have any thoughts?
My spec is testing code that creates a large object, 110 fields, with a lot of complex interrelationships. With your help, I got to this form:
describe “the object” do
before(:all) do
@obj = expensively_create_the_object
end
it “should exist” { @obj.should_not == nil }
it “should have proper field1″ { @obj.field1.should == 37 }
it “should have proper field2″ { @obj.field2.should == 19 }
…
end
I tried
specify { @obj.field2.should == 37 }
specify { @obj.field2.should == 19 }
…
which is more readable, but the test output says I pass or fail stuff like:
should == nil
should == nil
should == 3
should == “Demo”
should not == nil
should == nil
Is there any way to get specify to name the tested field?
]]>
context "when valid" do
it "should return 'January' for 1" # lower boundary
it "should return 'March' for 3"
it "should return 'December' for 12" # upper boundary
you missed end keyword.
]]>
describe User do
context "when name empty" do
it { should not be_valid }
specify { subject.save.should == false }
end
context "when name not empty" do
before { subject.name = 'Sam' }
it { should be_valid }
specify { subject.save.should == true }
end
describe :present do
subject { subject.present }
context "when user is a W" do
before { subject.gender = 'W' }
it { should be_a Flower }
end
context "when user is a M" do
before { subject.gender = 'M' }
it { should be_an IMac }
end
end
end
Good example of what you can do: http://gusiev.com/dorspec/#24
]]>