Created
May 14, 2012 03:03
-
-
Save dchelimsky/2691548 to your computer and use it in GitHub Desktop.
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 | |
it { should validate_presence_of(:title) } | |
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 "validates presence of :title" do | |
article = Article.new | |
article.should validate_presence_of(:title) | |
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 | |
subject { Article.new } | |
# ... |
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
# ... | |
it "validates presence of :title" do | |
subject.should validate_presence_of(:title) | |
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
# not recommended | |
describe Article do | |
subject { Article.new } | |
it "validates presence of :title" do | |
subject.should validate_presence_of(:title) | |
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 | |
def article; Article.new; end | |
it "validates presence of :title" do | |
article.should validate_presence_of(:title) | |
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
# refactoring toward implicit step 1 | |
describe Article do | |
it "validates presence of :title" do | |
subject.should validate_presence_of(:title) | |
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
# refactoring toward implicit step 2 | |
describe Article do | |
it "validates presence of :title" do | |
should validate_presence_of(:title) | |
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 | |
subject { Article.new :title => "Lorem ipsum" } | |
it "has a title" do | |
subject.title.should eq("Lorem ipsum") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment