Hi, I''m trying to make a very simple console game, and have been using RSpec. However, the ''have'' matcher is failing for some reason. I have a class named Game, which has a collection named Teams, defined as a read-only attribute. However, the following specification is failing: it { should have(1).teams } The code is here: http://gist.github.com/168572 It is the very last specification in the code that is failing. I''m running RSpec 1.2.8. Here''s the output: $ spec spec/ ...F 1) ''Game before it is started when a team is added should have 1 teams'' FAILED expected 1 teams, got 0 /home/Brandon/projects/baseball/spec/game_spec.rb:20: Finished in 0.05 seconds 4 examples, 1 failure When I manually call @game.teams.count, it returns 1, and the following spec succeeds: it "should have 1 team" do @game.teams.count.should == 1 end Thanks, Brandon
Hi, I''m really sorry, never mind on the matcher. I guess I remembered incorrectly how to set the subject. Is: Subject { @game } The best way to set it? Brandon -- www.creatorspiritus.com Blog and forum discussing living a Christ-centered life Follow me on Twitter: http://twitter.com/devbanana Follow creatorspiritus.com on Twitter: http://twitter.com/creatorspiritus
On Sun, Aug 16, 2009 at 2:46 AM, Brandon Olivares<programmer2188 at gmail.com> wrote:> Hi, > > I''m really sorry, never mind on the matcher. I guess I remembered > incorrectly how to set the subject. > > Is: > > Subject { @game }It''s with a lowercase ''s'': subject { @game } But if you call the subject method without a block you get an instance of Game (because that''s passed to describe()). Check out http://gist.github.com/168629 HTH, David> > The best way to set it? > > Brandon > > -- > www.creatorspiritus.com > Blog and forum discussing living a Christ-centered life > Follow me on Twitter: http://twitter.com/devbanana > Follow creatorspiritus.com on Twitter: http://twitter.com/creatorspiritus > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >