Created
October 12, 2010 19:19
-
-
Save ngauthier/622753 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Boat | |
| driveable | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe Boat | |
| it { should be_driveable } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Car | |
| driveable | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe Car | |
| it { should be_driveable } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # how do I define this and mix it into rspec? | |
| def be_driveable | |
| it 'should turn left' do | |
| @it.turn_left | |
| @it.angle.should == 270 | |
| end | |
| it 'should turn right' do | |
| @it.turn_right | |
| @it.angle.should == 90 | |
| end | |
| end |
Author
Thats what I ended up doing, but It ended up being longer than I wanted because I couldn't interpolate the model name. I had to set three separate subject with three separate shared examples, which was not ideal.
In Test::Unit I would have just make a test plugin the did some meta-programming to used the class names to generate the appropriate objects.
Maybe like this:
[Boat, Car].each do |vehicle|
describe vehicle do
it_behaves_like "a vehicle"
end
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe you should use RSpec shared examples ? (I didn't test those)
More info here: http://relishapp.com/rspec/rspec-core/v/2-0/dir/example-groups/shared-example-group