Last active
August 29, 2015 14:12
-
-
Save brysgo/abfb8c2ba5df8de33184 to your computer and use it in GitHub Desktop.
Linearly dependant tests in rspec
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
module BehaviorDSL | |
def behavior(name, &block) | |
metadata[:description_args].push(name) | |
refresh_description | |
yield | |
metadata[:description_args].pop | |
refresh_description | |
end | |
private | |
def refresh_description | |
metadata[:description] = metadata[:description_args].join(" ") | |
metadata[:full_description] = [metadata[:example_group][:full_description]].concat(metadata[:description_args]).join(" ") | |
end | |
def metadata | |
RSpec.current_example.metadata | |
end | |
end | |
RSpec.configure do |config| | |
config.include BehaviorDSL | |
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 Hash do | |
specify do | |
@hash = Hash.new | |
behavior "should set new keys properly" do | |
@hash[:foo] = 'bar' | |
@hash[:foo].should == 'bar' | |
end | |
behavior "overwrite old values with the same key" do | |
@hash[:foo] = 'baz' | |
@hash[:foo].should == 'baz' | |
end | |
end | |
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 Hash do | |
before do | |
@hash = Hash.new | |
end | |
it "should set new keys properly" do | |
@hash[:foo] = 'bar' | |
@hash[:foo].should == 'bar' | |
end | |
it "overwrite old values with the same key" do | |
@hash[:foo] = 'bar' | |
@hash[:foo].should == 'bar' | |
@hash[:foo] = 'baz' | |
@hash[:foo].should == 'baz' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment