-
-
Save bjeanes/1382828 to your computer and use it in GitHub Desktop.
Spectastrophe #1
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
# This assumes `is_appropriate?` is renamed to `appropriate?` which is more idiomatic anyway | |
describe FashionSituation do | |
describe "#is_appropriate?" do | |
context "when wearing only shorts" do | |
let(:wearing_only_shorts) { FashionSituation.new(:shirt => false, :shoes => false, :shorts => true, :location => location) } | |
subject { wearing_only_shorts } | |
context "at a restaurant" do | |
let(:location) { "restaurant" } | |
it { should_not be_appropriate } | |
end | |
context "at work" do | |
let(:location) { "work" } | |
it { should_not be_appropriate } | |
end | |
context "at the beach" do | |
let(:location) { "beach" } | |
it { should be_appropriate } | |
end | |
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 FashionSituation do | |
it "should be inappropriate at a restaurant" do | |
situation = FashionSituation.new(:shirt => false, :shoes => false, :shorts => true, :location => "restaurant") | |
situation.should_not be_appropriate | |
end | |
it "should be inappropriate at work" do | |
situation = FashionSituation.new(:shirt => false, :shoes => false, :shorts => true, :location => "work") | |
situation.should_not be_appropriate | |
end | |
it "should be appropriate at the beach" do | |
situation = FashionSituation.new(:shirt => false, :shoes => false, :shorts => true, :location => "beach") | |
situation.should be_appropriate | |
end | |
end | |
#### OR making this slightly more realistic, and talking about valid versus invalid | |
# that actually is a case where I think having shared setup between tests is appropriate, because your tests really are really only valuable as a whole. a single one doesn't really prove anything | |
describe FashionSituation do | |
before { @situation = FashionSituation.new(:shirt => false, :shoes => false, :shorts => true, :location => "beach") } | |
it "should be invalid at a restaurant" do | |
@situation.location = 'restaurant' | |
situation.should_not be_valid | |
end | |
it "should be invalid at work" do | |
@situation.location = 'work' | |
situation.should_not be_valid | |
end | |
it "should be valid when setup properly" do | |
@situation.should be_valid | |
end | |
end | |
# Though, generally with these you could just have | |
describe FashionSituation do | |
it "should be invalid at a restaurant" do | |
Factory.build(:fashion_situation, :location => 'restaurant').should_not be_valid | |
end | |
it "should be invalid at work" do | |
Factory.build(:fashion_situation, :location => 'work').should_not be_valid | |
end | |
it "should be valid when setup properly" do | |
Factory.build(:fashion_situation, :location => 'beach').should be_valid | |
end | |
end | |
# not 100% sure which of these 2 I prefer, but I think the one with the before is more obvious and involves less hoops |
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 FashionSituation do | |
describe "#is_appropriate?" do | |
context "at a restaurant" do | |
before do | |
@situation = FashionSituation.new(:shirt => false, :shoes => false, :shorts => true, :location => "restaurant") | |
end | |
it "should be inappropriate" do | |
@situation.should_not be_appropriate | |
end | |
end | |
context "at work" do | |
before do | |
@situation = FashionSituation.new(:shirt => false, :shoes => false, :shorts => true, :location => "work") | |
end | |
it "should be inappropriate" do | |
@situation.should_not be_appropriate | |
end | |
end | |
context "at the beach" do | |
before do | |
@situation = FashionSituation.new(:shirt => false, :shoes => false, :shorts => true, :location => "beach") | |
end | |
it "should be appropriate" do | |
@situation.should be_appropriate | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment