Created
August 22, 2011 22:43
-
-
Save garybernhardt/1163843 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
# mock-based (interaction) | |
# db independent, but tied to implementation (I can change the AR call without affecting the behavior and this will fail) | |
context "data gathering" do | |
it "finds all indicators associated with the given sector and includes indicators not associated with any sectors" do | |
sector = stub_model(Sector, :id => 6) | |
Indicator.should_receive(:where).with("sector_id is null or sector_id = ?", sector.id) | |
Indicator.for_sector(sector) | |
end | |
end | |
# traditional (data-based) | |
# slower but focused on behavior, doesn't verify the interaction, but also doesn't ties the spec to the AR finder | |
context "data gathering" do | |
it "finds all indicators associated with the given sector and includes indicators not associated with any sectors" do | |
sector = Factory(:sector) | |
indicators = Array.new(2) { Factory(:indicator, :sector => sector) } | |
indicators << Factory(:indicator) | |
2.times { Factory(:indicator, :sector => Factory(:sector)) } | |
Indicator.for_sector(sector).should eq(indicators) | |
end | |
end | |
# integrated with model with fine-grained assertions | |
context "#for_sector" do | |
let(:sector) { Factory(:sector) } | |
it "finds indicators with no sector" do | |
indicator = Factory(:indicator) | |
Indicator.for_sector(sector).should == [indicator] | |
end | |
it "finds indicators with the given sector" do | |
indicator = Factory(:indicator, :sector => sector) | |
Indicator.for_sector(sector).should == [indicator] | |
end | |
it "ignores indicators associated with other sectors" do | |
indicator = Factory(:indicator, :sector => Factory(:sector)) | |
Indicator.for_sector(sector).should == [] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment