Created
May 26, 2010 05:55
-
-
Save pcreux/414120 to your computer and use it in GitHub Desktop.
This file contains 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
require 'rspec' | |
def set(attribute, &block) | |
before(:all) do | |
instance_variable_set("@#{attribute}", yield) | |
end | |
let(attribute) { instance_variable_get("@#{attribute}") } | |
end | |
class Foo | |
attr_reader :bar | |
def initialize(i = 0) | |
@bar = i | |
end | |
def bar! | |
@bar += 1 | |
end | |
end | |
describe :set do | |
set(:foo) { Foo.new } | |
let(:foo2) { Foo.new } | |
set(:foo3) { Foo.new(10) } | |
it "should have foo.bar == 0" do | |
foo.bar.should == 0 | |
end | |
it "should have foo2.bar == 0" do | |
foo2.bar.should == 0 | |
end | |
it "should have foo3.bar == 10" do | |
foo3.bar.should == 10 | |
end | |
context "when incremented" do | |
before(:all) do | |
foo.bar! | |
foo2.bar! | |
foo3.bar! | |
end | |
it "should have foo.bar == 1" do | |
foo.bar.should == 1 | |
end | |
it "should have foo2.bar == 0" do | |
foo2.bar.should == 1 | |
end | |
it "should have foo3.bar == 11" do | |
foo3.bar.should == 11 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment