Created
May 15, 2012 00:26
-
-
Save dchelimsky/2698271 to your computer and use it in GitHub Desktop.
More source examples for blog on explicit use of subject
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 Article do | |
def article; Article.new :title => "Lorem ipsum"; end | |
it "has a title" do | |
article.title.should eq("Lorem ipsum") | |
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 Article do | |
it "has a title" do | |
article = Article.new :title => "Lorem ipsum" | |
article.title.should eq("Lorem ipsum") | |
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
# before | |
shared_exmamples_for "an auditable object" do | |
it "creates an audit record on save!" do | |
lambda { subject.save! }.should change(Audit, :count).by(1) | |
end | |
end | |
describe Person do | |
it_behaves_like "an auditable object" do | |
subject { Person.new :name => "David" } | |
end | |
end | |
# after | |
shared_exmamples_for "an auditable object" do | |
it "creates an audit record on save!" do | |
lambda { auditable.save! }.should change(Audit, :count).by(1) | |
# ^ ^ ^ ^ ^ | |
end | |
end | |
describe Person do | |
it_behaves_like "an auditable object" do | |
def auditable; Person.new :name => "David"; 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 AmericanCitizen do | |
context "18 years of age" do | |
subject { Person.new(:birthdate => 18.years.ago) } | |
it { should be_able_to(:vote) } | |
it { should be_able_to(:enlist) } | |
it { should_not be_able_to(:drink) } # srsly? | |
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 CheckingAccount, "with a non-zero starting balance" do | |
subject(:account) { CheckingAccount.new(Money.new(50, :USD)) } | |
it { should_not be_overdrawn } | |
it "has a balance equal to the starting balance" do | |
account.balance.should eq(Money.new(50, :USD)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment