Andrew WC Brown
2007-Oct-05 21:44 UTC
[rspec-users] spec''ing view render partial collection, local variable not found
I''m trying to spec out a render partial collection but I get the following error 2) NoMethodError in ''/games/_game.rhtml should show game name'' undefined method `body'' for #<#<Class:0x316580c>:0x2f1154c> /Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in `matches?'' ./spec/views/games/_game.rhtml_spec.rb:39: def before game = mock_model(Game, :name => ''The Battle for Blaze'', :salt_grains => 5000000, :people => 5000000, :days => nil, :created_at => "Mon Oct 01 00:02:44 -0400 2007", :enabled => true) game.should_receive(:name).and_return("The Battle for Blaze") game.should_receive(:salt_grains).and_return(5000000) game.should_receive(:people).and_return(5000000) game.should_receive(:days).and_return(nil) game.should_receive(:created_at).and_return("Mon Oct 01 00:02:44 -0400 2007") game.should_receive(:enabled).and_return(true) assigns[:games] = [game] end it "should show game name" do template.should have_text(/The Battle for Blaze/) render :partial =>"game", :collection => @games end -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071005/7acefbd4/attachment.html
David Chelimsky
2007-Oct-05 21:45 UTC
[rspec-users] spec''ing view render partial collection, local variable not found
On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote:> I''m trying to spec out a render partial collection but I get the following > error > > 2) > NoMethodError in ''/games/_game.rhtml should show game name'' > undefined method `body'' for #<#<Class:0x316580c>:0x2f1154c> > /Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in > `matches?'' > ./spec/views/games/_game.rhtml_spec.rb:39: > > def before > game = mock_model(Game, > :name => ''The Battle for Blaze'', > :salt_grains => 5000000, > :people => 5000000, > :days => nil, > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > :enabled => true) > game.should_receive(:name).and_return("The Battle for Blaze") > game.should_receive(:salt_grains).and_return(5000000) > game.should_receive(:people).and_return(5000000) > game.should_receive(:days).and_return(nil) > game.should_receive(:created_at).and_return("Mon Oct 01 00:02:44 -0400 > 2007") > game.should_receive(:enabled).and_return(true) > > > assigns[:games] = [game] > end > > it "should show game name" do > template.should have_text(/The Battle for Blaze/)response.should have_text .... (not template.should ...)> render :partial =>"game", :collection => @games > end > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Andrew WC Brown
2007-Oct-05 22:09 UTC
[rspec-users] spec''ing view render partial collection, local variable not found
1) ''/games/_game.rhtml should show game name'' FAILED expected /The Battle for Blaze/, got "" ./spec/views/games/_game.rhtml_spec.rb:39: def before game_1 = mock_model(Game, :name => ''The Battle for Blaze'', :salt_grains => 5000000, :people => 5000000, :days => nil, :created_at => "Mon Oct 01 00:02:44 -0400 2007", :enabled => true) game_1.should_receive(:name).and_return("The Battle for Blaze") game_1.should_receive(:salt_grains).and_return(5000000) game_1.should_receive(:people).and_return(5000000) game_1.should_receive(:days).and_return(nil) game_1.should_receive(:created_at).and_return("Mon Oct 01 00:02:44 -0400 2007") game_1.should_receive(:enabled).and_return(true) game_2 = mock_model(Game, :name => ''Epicbattlegrounds'', :salt_grains => 30000000, :people => 20000000, :days => 100, :created_at => "Mon Sept 01 12:02:44 -0400 2007", :enabled => false) game_2.should_receive(:name).and_return("Epicbattlegrounds") game_2.should_receive(:salt_grains).and_return(30000000) game_2.should_receive(:people).and_return(20000000) game_2.should_receive(:days).and_return(100) game_2.should_receive(:created_at).and_return("Mon Sept 01 12:02:44 -0400 2007") game_2.should_receive(:enabled).and_return(false) @games = [game_1, game_2] assigns[:games] = [game_1, game_2] end it "should show game name" do response.should have_text(/The Battle for Blaze/) render :partial =>"game", :collection => @games end I think the local variable is showing up nil because my specs in the index.rhtml were failing when they were fine before and they were saying they didn''t know what this game variable was. Any ideas? On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote:> > On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote: > > I''m trying to spec out a render partial collection but I get the > following > > error > > > > 2) > > NoMethodError in ''/games/_game.rhtml should show game name'' > > undefined method `body'' for #<#<Class:0x316580c>:0x2f1154c> > > > /Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in > > `matches?'' > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > def before > > game = mock_model(Game, > > :name => ''The Battle for Blaze'', > > :salt_grains => 5000000, > > :people => 5000000, > > :days => nil, > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > :enabled => true) > > game.should_receive(:name).and_return("The Battle for Blaze") > > game.should_receive(:salt_grains).and_return(5000000) > > game.should_receive(:people).and_return(5000000) > > game.should_receive(:days).and_return(nil) > > game.should_receive(:created_at).and_return("Mon Oct 01 00:02:44 > -0400 > > 2007") > > game.should_receive(:enabled).and_return(true) > > > > > > assigns[:games] = [game] > > end > > > > it "should show game name" do > > template.should have_text(/The Battle for Blaze/) > > response.should have_text .... > > (not template.should ...) > > > render :partial =>"game", :collection => @games > > end > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071005/609e8707/attachment-0001.html
David Chelimsky
2007-Oct-05 22:11 UTC
[rspec-users] spec''ing view render partial collection, local variable not found
On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote:> 1) > ''/games/_game.rhtml should show game name'' FAILED > expected /The Battle for Blaze/, got "" > ./spec/views/games/_game.rhtml_spec.rb:39: > > def before > game_1 = mock_model(Game, > :name => ''The Battle for Blaze'', > :salt_grains => 5000000, > :people => 5000000, > :days => nil, > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > :enabled => true) > game_1.should_receive(:name).and_return("The Battle for > Blaze") > game_1.should_receive(:salt_grains).and_return(5000000) > game_1.should_receive(:people).and_return(5000000) > game_1.should_receive(:days).and_return(nil) > game_1.should_receive(:created_at).and_return("Mon Oct > 01 00:02:44 -0400 2007") > game_1.should_receive(:enabled).and_return(true) > > game_2 = mock_model(Game, > :name => ''Epicbattlegrounds'', > :salt_grains => 30000000, > :people => 20000000, > :days => 100, > :created_at => "Mon Sept 01 12:02:44 -0400 2007", > :enabled => false) > > game_2.should_receive(:name).and_return("Epicbattlegrounds") > > game_2.should_receive(:salt_grains).and_return(30000000) > game_2.should_receive(:people).and_return(20000000) > game_2.should_receive(:days).and_return(100) > game_2.should_receive(:created_at).and_return("Mon Sept > 01 12:02:44 -0400 2007") > game_2.should_receive(:enabled).and_return(false) > @games = [game_1, game_2] > assigns[:games] = [game_1, game_2] > end > > it "should show game name" do > response.should have_text(/The Battle for Blaze/) > render :partial =>"game", :collection => @gamesSwitch these around: render :partial =>"game", :collection => @games response.should have_text(/The Battle for Blaze/)> end > > I think the local variable is showing up nil because my specs in the > index.rhtml were failing when they were fine before and they were saying > they didn''t know what this game variable was. > > Any ideas? > > > On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote: > > > I''m trying to spec out a render partial collection but I get the > following > > > error > > > > > > 2) > > > NoMethodError in ''/games/_game.rhtml should show game name'' > > > undefined method `body'' for #<#<Class:0x316580c>:0x2f1154c> > > > > /Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in > > > `matches?'' > > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > > > def before > > > game = mock_model(Game, > > > :name => ''The Battle for Blaze'', > > > :salt_grains => 5000000, > > > :people => 5000000, > > > :days => nil, > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > :enabled => true) > > > game.should_receive(:name).and_return("The Battle for Blaze") > > > > game.should_receive(:salt_grains).and_return(5000000) > > > game.should_receive(:people).and_return(5000000) > > > game.should_receive(:days).and_return(nil) > > > game.should_receive(:created_at).and_return("Mon Oct 01 00:02:44 > -0400 > > > 2007") > > > game.should_receive(:enabled).and_return(true) > > > > > > > > > assigns[:games] = [game] > > > end > > > > > > it "should show game name" do > > > template.should have_text(/The Battle for Blaze/) > > > > response.should have_text .... > > > > (not template.should ...) > > > > > render :partial =>"game", :collection => @games > > > end > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Andrew WC Brown
2007-Oct-05 22:17 UTC
[rspec-users] spec''ing view render partial collection, local variable not found
Well when I saw that originally thats what I thought the response was suppose to come after the render but: ActionView::ActionViewError in ''/games/_game.rhtml should show game name'' No rhtml, rxml, rjs or delegate template found for //_game in /Volumes/EXTERNAL/web/omenking.ca/config/../app/views games/_game.rhtml does exist. which maybe I have to state: it "should show game name" do render :partial =>"games/game", :collection => @games response.should have_text(/The Battle for Blaze/) end but then: 1) ActionView::TemplateError in ''/games/_game.rhtml should show game name'' You have a nil object when you didn''t expect it! The error occurred while evaluating nil.name On line #1 of app/views/games/_game.rhtml 1: <%= h game.name %> so the local variable is show up nil. On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote:> > On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote: > > 1) > > ''/games/_game.rhtml should show game name'' FAILED > > expected /The Battle for Blaze/, got "" > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > def before > > game_1 = mock_model(Game, > > :name => ''The Battle for Blaze'', > > :salt_grains => 5000000, > > :people => 5000000, > > :days => nil, > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > :enabled => true) > > game_1.should_receive(:name).and_return("The Battle for > > Blaze") > > game_1.should_receive(:salt_grains).and_return(5000000) > > game_1.should_receive(:people).and_return(5000000) > > game_1.should_receive(:days).and_return(nil) > > game_1.should_receive(:created_at).and_return("Mon Oct > > 01 00:02:44 -0400 2007") > > game_1.should_receive(:enabled).and_return(true) > > > > game_2 = mock_model(Game, > > :name => ''Epicbattlegrounds'', > > :salt_grains => 30000000, > > :people => 20000000, > > :days => 100, > > :created_at => "Mon Sept 01 12:02:44 -0400 2007", > > :enabled => false) > > > > game_2.should_receive(:name).and_return("Epicbattlegrounds") > > > > game_2.should_receive(:salt_grains).and_return(30000000) > > game_2.should_receive(:people).and_return(20000000) > > game_2.should_receive(:days).and_return(100) > > game_2.should_receive(:created_at).and_return("Mon Sept > > 01 12:02:44 -0400 2007") > > game_2.should_receive(:enabled).and_return(false) > > @games = [game_1, game_2] > > assigns[:games] = [game_1, game_2] > > end > > > > it "should show game name" do > > response.should have_text(/The Battle for Blaze/) > > render :partial =>"game", :collection => @games > > Switch these around: > > render :partial =>"game", :collection => @games > response.should have_text(/The Battle for Blaze/) > > > > end > > > > I think the local variable is showing up nil because my specs in the > > index.rhtml were failing when they were fine before and they were saying > > they didn''t know what this game variable was. > > > > Any ideas? > > > > > > On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote: > > > > I''m trying to spec out a render partial collection but I get the > > following > > > > error > > > > > > > > 2) > > > > NoMethodError in ''/games/_game.rhtml should show game name'' > > > > undefined method `body'' for #<#<Class:0x316580c>:0x2f1154c> > > > > > > > /Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in > > > > `matches?'' > > > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > > > > > def before > > > > game = mock_model(Game, > > > > :name => ''The Battle for Blaze'', > > > > :salt_grains => 5000000, > > > > :people => 5000000, > > > > :days => nil, > > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > > :enabled => true) > > > > game.should_receive(:name).and_return("The Battle for Blaze") > > > > > > game.should_receive(:salt_grains).and_return(5000000) > > > > game.should_receive(:people).and_return(5000000) > > > > game.should_receive(:days).and_return(nil) > > > > game.should_receive(:created_at).and_return("Mon Oct 01 00:02:44 > > -0400 > > > > 2007") > > > > game.should_receive(:enabled).and_return(true) > > > > > > > > > > > > assigns[:games] = [game] > > > > end > > > > > > > > it "should show game name" do > > > > template.should have_text(/The Battle for Blaze/) > > > > > > response.should have_text .... > > > > > > (not template.should ...) > > > > > > > render :partial =>"game", :collection => @games > > > > end > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071005/17ae3706/attachment.html
David Chelimsky
2007-Oct-05 22:25 UTC
[rspec-users] spec''ing view render partial collection, local variable not found
On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote:> Well when I saw that originally thats what I thought the response was > suppose to come after the render but: > > ActionView::ActionViewError in ''/games/_game.rhtml should show game name'' > No rhtml, rxml, rjs or delegate template found for //_game in > /Volumes/EXTERNAL/web/omenking.ca/config/../app/views > > games/_game.rhtml does exist. > > which maybe I have to state: > > it "should show game name" do > render :partial =>"games/game", :collection => @games > response.should have_text(/The Battle for Blaze/) > end > > but then: > > 1) > ActionView::TemplateError in ''/games/_game.rhtml should show game name'' > You have a nil object when you didn''t expect it! > The error occurred while evaluating nil.name > On line #1 of app/views/games/_game.rhtml > > 1: <%= h game.name %> > > so the local variable is show up nil.:collection is something rails uses to render a template multiple times. RSpec only renders the file once (as intended). Try using :object: render :partial =>"games/game", :object => @game (of course, you''ll have to have setup @game).> > > On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote: > > > 1) > > > ''/games/_game.rhtml should show game name'' FAILED > > > expected /The Battle for Blaze/, got "" > > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > > > def before > > > game_1 = mock_model(Game, > > > :name => ''The Battle for Blaze'', > > > :salt_grains => 5000000, > > > :people => 5000000, > > > :days => nil, > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > :enabled => true) > > > game_1.should_receive(:name).and_return("The Battle > for > > > Blaze") > > > > game_1.should_receive(:salt_grains).and_return(5000000) > > > game_1.should_receive(:people).and_return(5000000) > > > game_1.should_receive(:days).and_return(nil) > > > game_1.should_receive(:created_at).and_return("Mon > Oct > > > 01 00:02:44 -0400 2007") > > > game_1.should_receive(:enabled).and_return(true) > > > > > > game_2 = mock_model(Game, > > > :name => ''Epicbattlegrounds'', > > > :salt_grains => 30000000, > > > :people => 20000000, > > > :days => 100, > > > :created_at => "Mon Sept 01 12:02:44 -0400 2007", > > > :enabled => false) > > > > > > > game_2.should_receive(:name).and_return("Epicbattlegrounds") > > > > > > > game_2.should_receive(:salt_grains).and_return(30000000) > > > game_2.should_receive(:people).and_return(20000000) > > > game_2.should_receive(:days).and_return(100) > > > game_2.should_receive(:created_at).and_return("Mon > Sept > > > 01 12:02:44 -0400 2007") > > > game_2.should_receive(:enabled).and_return(false) > > > @games = [game_1, game_2] > > > assigns[:games] = [game_1, game_2] > > > end > > > > > > it "should show game name" do > > > response.should have_text(/The Battle for Blaze/) > > > render :partial =>"game", :collection => @games > > > > Switch these around: > > > > render :partial =>"game", :collection => @games > > response.should have_text(/The Battle for Blaze/) > > > > > > > end > > > > > > I think the local variable is showing up nil because my specs in the > > > index.rhtml were failing when they were fine before and they were saying > > > they didn''t know what this game variable was. > > > > > > Any ideas? > > > > > > > > > On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > On 10/5/07, Andrew WC Brown < omen.king at gmail.com> wrote: > > > > > I''m trying to spec out a render partial collection but I get the > > > following > > > > > error > > > > > > > > > > 2) > > > > > NoMethodError in ''/games/_game.rhtml should show game name'' > > > > > undefined method `body'' for #<#<Class:0x316580c>:0x2f1154c> > > > > > > > > > /Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in > > > > > `matches?'' > > > > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > > > > > > > def before > > > > > game = mock_model(Game, > > > > > :name => ''The Battle for Blaze'', > > > > > :salt_grains => 5000000, > > > > > :people => 5000000, > > > > > :days => nil, > > > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > > > :enabled => true) > > > > > game.should_receive(:name).and_return("The Battle for Blaze") > > > > > > > > game.should_receive(:salt_grains).and_return(5000000) > > > > > game.should_receive(:people).and_return(5000000) > > > > > game.should_receive(:days).and_return(nil) > > > > > game.should_receive(:created_at).and_return("Mon Oct 01 00:02:44 > > > -0400 > > > > > 2007") > > > > > game.should_receive(:enabled).and_return(true) > > > > > > > > > > > > > > > assigns[:games] = [game] > > > > > end > > > > > > > > > > it "should show game name" do > > > > > template.should have_text(/The Battle for Blaze/) > > > > > > > > response.should have_text .... > > > > > > > > (not template.should ...) > > > > > > > > > render :partial =>"game", :collection => @games > > > > > end > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
David Chelimsky
2007-Oct-05 23:45 UTC
[rspec-users] spec''ing view render partial collection, local variable not found
On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote:> On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote: > > Well when I saw that originally thats what I thought the response was > > suppose to come after the render but: > > > > ActionView::ActionViewError in ''/games/_game.rhtml should show game name'' > > No rhtml, rxml, rjs or delegate template found for //_game in > > /Volumes/EXTERNAL/web/omenking.ca/config/../app/views > > > > games/_game.rhtml does exist. > > > > which maybe I have to state: > > > > it "should show game name" do > > render :partial =>"games/game", :collection => @games > > response.should have_text(/The Battle for Blaze/) > > end > > > > but then: > > > > 1) > > ActionView::TemplateError in ''/games/_game.rhtml should show game name'' > > You have a nil object when you didn''t expect it! > > The error occurred while evaluating nil.name > > On line #1 of app/views/games/_game.rhtml > > > > 1: <%= h game.name %> > > > > so the local variable is show up nil. > > :collection is something rails uses to render a template multiple > times. RSpec only renders the file once (as intended). Try using > :object: > > render :partial =>"games/game", :object => @game > > (of course, you''ll have to have setup @game).That do the trick?> > > > > > > On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > > > On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote: > > > > 1) > > > > ''/games/_game.rhtml should show game name'' FAILED > > > > expected /The Battle for Blaze/, got "" > > > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > > > > > def before > > > > game_1 = mock_model(Game, > > > > :name => ''The Battle for Blaze'', > > > > :salt_grains => 5000000, > > > > :people => 5000000, > > > > :days => nil, > > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > > :enabled => true) > > > > game_1.should_receive(:name).and_return("The Battle > > for > > > > Blaze") > > > > > > game_1.should_receive(:salt_grains).and_return(5000000) > > > > game_1.should_receive(:people).and_return(5000000) > > > > game_1.should_receive(:days).and_return(nil) > > > > game_1.should_receive(:created_at).and_return("Mon > > Oct > > > > 01 00:02:44 -0400 2007") > > > > game_1.should_receive(:enabled).and_return(true) > > > > > > > > game_2 = mock_model(Game, > > > > :name => ''Epicbattlegrounds'', > > > > :salt_grains => 30000000, > > > > :people => 20000000, > > > > :days => 100, > > > > :created_at => "Mon Sept 01 12:02:44 -0400 2007", > > > > :enabled => false) > > > > > > > > > > game_2.should_receive(:name).and_return("Epicbattlegrounds") > > > > > > > > > > game_2.should_receive(:salt_grains).and_return(30000000) > > > > game_2.should_receive(:people).and_return(20000000) > > > > game_2.should_receive(:days).and_return(100) > > > > game_2.should_receive(:created_at).and_return("Mon > > Sept > > > > 01 12:02:44 -0400 2007") > > > > game_2.should_receive(:enabled).and_return(false) > > > > @games = [game_1, game_2] > > > > assigns[:games] = [game_1, game_2] > > > > end > > > > > > > > it "should show game name" do > > > > response.should have_text(/The Battle for Blaze/) > > > > render :partial =>"game", :collection => @games > > > > > > Switch these around: > > > > > > render :partial =>"game", :collection => @games > > > response.should have_text(/The Battle for Blaze/) > > > > > > > > > > end > > > > > > > > I think the local variable is showing up nil because my specs in the > > > > index.rhtml were failing when they were fine before and they were saying > > > > they didn''t know what this game variable was. > > > > > > > > Any ideas? > > > > > > > > > > > > On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > > On 10/5/07, Andrew WC Brown < omen.king at gmail.com> wrote: > > > > > > I''m trying to spec out a render partial collection but I get the > > > > following > > > > > > error > > > > > > > > > > > > 2) > > > > > > NoMethodError in ''/games/_game.rhtml should show game name'' > > > > > > undefined method `body'' for #<#<Class:0x316580c>:0x2f1154c> > > > > > > > > > > > > /Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in > > > > > > `matches?'' > > > > > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > > > > > > > > > def before > > > > > > game = mock_model(Game, > > > > > > :name => ''The Battle for Blaze'', > > > > > > :salt_grains => 5000000, > > > > > > :people => 5000000, > > > > > > :days => nil, > > > > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > > > > :enabled => true) > > > > > > game.should_receive(:name).and_return("The Battle for Blaze") > > > > > > > > > > game.should_receive(:salt_grains).and_return(5000000) > > > > > > game.should_receive(:people).and_return(5000000) > > > > > > game.should_receive(:days).and_return(nil) > > > > > > game.should_receive(:created_at).and_return("Mon Oct 01 00:02:44 > > > > -0400 > > > > > > 2007") > > > > > > game.should_receive(:enabled).and_return(true) > > > > > > > > > > > > > > > > > > assigns[:games] = [game] > > > > > > end > > > > > > > > > > > > it "should show game name" do > > > > > > template.should have_text(/The Battle for Blaze/) > > > > > > > > > > response.should have_text .... > > > > > > > > > > (not template.should ...) > > > > > > > > > > > render :partial =>"game", :collection => @games > > > > > > end > > > > > > > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > >
Andrew WC Brown
2007-Oct-06 00:00 UTC
[rspec-users] spec''ing view render partial collection, local variable not found
Well I think my biggest problem I was having was the fact that my before block was: def before end instead of before do end So I think its working, although my mock is complaining now: before do game = mock_model(Game, :name => ''The Battle for Blaze'', :salt_grains => 5000000, :people => 5000000, :days => nil, :created_at => "Mon Oct 01 00:02:44 -0400 2007", :enabled => true) game.should_receive(:name).and_return(''The Battle for Blaze'') game.should_receive(:salt_grains).and_return(5000000) game.should_receive(:people).and_return(5000000) game.should_receive(:days).and_return(nil) game.should_receive(:created_at).and_return("Mon Oct 01 00:02:44 -0400 2007") game.should_receive(:enabled).and_return(true) @game = game end 1) Spec::Mocks::MockExpectationError in ''/games/_game.rhtml should show game name'' Mock ''Game_1082'' expected :salt_grains with (any args) once, but received it 0 times ./spec/views/games/_game.rhtml_spec.rb:15: On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote:> > On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote: > > Well when I saw that originally thats what I thought the response was > > suppose to come after the render but: > > > > ActionView::ActionViewError in ''/games/_game.rhtml should show game > name'' > > No rhtml, rxml, rjs or delegate template found for //_game in > > /Volumes/EXTERNAL/web/omenking.ca/config/../app/views > > > > games/_game.rhtml does exist. > > > > which maybe I have to state: > > > > it "should show game name" do > > render :partial =>"games/game", :collection => @games > > response.should have_text(/The Battle for Blaze/) > > end > > > > but then: > > > > 1) > > ActionView::TemplateError in ''/games/_game.rhtml should show game name'' > > You have a nil object when you didn''t expect it! > > The error occurred while evaluating nil.name > > On line #1 of app/views/games/_game.rhtml > > > > 1: <%= h game.name %> > > > > so the local variable is show up nil. > > :collection is something rails uses to render a template multiple > times. RSpec only renders the file once (as intended). Try using > :object: > > render :partial =>"games/game", :object => @game > > (of course, you''ll have to have setup @game). > > > > > > > On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > > > On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote: > > > > 1) > > > > ''/games/_game.rhtml should show game name'' FAILED > > > > expected /The Battle for Blaze/, got "" > > > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > > > > > def before > > > > game_1 = mock_model(Game, > > > > :name => ''The Battle for Blaze'', > > > > :salt_grains => 5000000, > > > > :people => 5000000, > > > > :days => nil, > > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > > :enabled => true) > > > > game_1.should_receive(:name).and_return("The Battle > > for > > > > Blaze") > > > > > > game_1.should_receive(:salt_grains).and_return(5000000) > > > > game_1.should_receive(:people).and_return(5000000) > > > > game_1.should_receive(:days).and_return(nil) > > > > game_1.should_receive(:created_at).and_return("Mon > > Oct > > > > 01 00:02:44 -0400 2007") > > > > game_1.should_receive(:enabled).and_return(true) > > > > > > > > game_2 = mock_model(Game, > > > > :name => ''Epicbattlegrounds'', > > > > :salt_grains => 30000000, > > > > :people => 20000000, > > > > :days => 100, > > > > :created_at => "Mon Sept 01 12:02:44 -0400 2007", > > > > :enabled => false) > > > > > > > > > > game_2.should_receive(:name).and_return("Epicbattlegrounds") > > > > > > > > > > game_2.should_receive(:salt_grains).and_return(30000000) > > > > game_2.should_receive(:people).and_return(20000000) > > > > game_2.should_receive(:days).and_return(100) > > > > game_2.should_receive(:created_at).and_return("Mon > > Sept > > > > 01 12:02:44 -0400 2007") > > > > game_2.should_receive(:enabled).and_return(false) > > > > @games = [game_1, game_2] > > > > assigns[:games] = [game_1, game_2] > > > > end > > > > > > > > it "should show game name" do > > > > response.should have_text(/The Battle for Blaze/) > > > > render :partial =>"game", :collection => @games > > > > > > Switch these around: > > > > > > render :partial =>"game", :collection => @games > > > response.should have_text(/The Battle for Blaze/) > > > > > > > > > > end > > > > > > > > I think the local variable is showing up nil because my specs in the > > > > index.rhtml were failing when they were fine before and they were > saying > > > > they didn''t know what this game variable was. > > > > > > > > Any ideas? > > > > > > > > > > > > On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > > On 10/5/07, Andrew WC Brown < omen.king at gmail.com> wrote: > > > > > > I''m trying to spec out a render partial collection but I get the > > > > following > > > > > > error > > > > > > > > > > > > 2) > > > > > > NoMethodError in ''/games/_game.rhtml should show game name'' > > > > > > undefined method `body'' for #<#<Class:0x316580c>:0x2f1154c> > > > > > > > > > > > > > /Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in > > > > > > `matches?'' > > > > > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > > > > > > > > > def before > > > > > > game = mock_model(Game, > > > > > > :name => ''The Battle for Blaze'', > > > > > > :salt_grains => 5000000, > > > > > > :people => 5000000, > > > > > > :days => nil, > > > > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > > > > :enabled => true) > > > > > > game.should_receive(:name).and_return("The Battle for > Blaze") > > > > > > > > > > game.should_receive(:salt_grains).and_return(5000000) > > > > > > game.should_receive(:people).and_return(5000000) > > > > > > game.should_receive(:days).and_return(nil) > > > > > > game.should_receive(:created_at).and_return("Mon Oct 01 > 00:02:44 > > > > -0400 > > > > > > 2007") > > > > > > game.should_receive(:enabled).and_return(true) > > > > > > > > > > > > > > > > > > assigns[:games] = [game] > > > > > > end > > > > > > > > > > > > it "should show game name" do > > > > > > template.should have_text(/The Battle for Blaze/) > > > > > > > > > > response.should have_text .... > > > > > > > > > > (not template.should ...) > > > > > > > > > > > render :partial =>"game", :collection => @games > > > > > > end > > > > > > > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071005/b4a7c82c/attachment-0001.html
David Chelimsky
2007-Oct-06 00:06 UTC
[rspec-users] spec''ing view render partial collection, local variable not found
On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote:> Well I think my biggest problem I was having was the fact that my before > block was: > > def before > end > > instead of > > before do > endD''oh - can''t believe I missed that.> > So I think its working, although my mock is complaining now: > before do > game = mock_model(Game, > :name => ''The Battle for Blaze'', > :salt_grains => 5000000, > :people => 5000000, > :days => nil, > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > :enabled => true) > game.should_receive(:name).and_return(''The Battle for Blaze'') > game.should_receive (:salt_grains).and_return(5000000) > game.should_receive(:people).and_return(5000000) > game.should_receive(:days).and_return(nil) > game.should_receive(:created_at).and_return("Mon Oct 01 00:02:44 -0400 > 2007") > game.should_receive(:enabled).and_return(true) > @game = game > end > > 1) > Spec::Mocks::MockExpectationError in ''/games/_game.rhtml > should show game name'' > Mock ''Game_1082'' expected :salt_grains with (any args) once, but received it > 0 times > ./spec/views/games/_game.rhtml_spec.rb:15:I''d need to see the full listing of both spec and code as they are now to help you w/ that.> > > On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > On 10/5/07, Andrew WC Brown <omen.king at gmail.com > wrote: > > > Well when I saw that originally thats what I thought the response was > > > suppose to come after the render but: > > > > > > ActionView::ActionViewError in ''/games/_game.rhtml should show game > name'' > > > No rhtml, rxml, rjs or delegate template found for //_game in > > > /Volumes/EXTERNAL/web/omenking.ca/config/../app/views > > > > > > games/_game.rhtml does exist. > > > > > > which maybe I have to state: > > > > > > it "should show game name" do > > > render :partial =>"games/game", :collection => @games > > > response.should have_text(/The Battle for Blaze/) > > > end > > > > > > but then: > > > > > > 1) > > > ActionView::TemplateError in ''/games/_game.rhtml should show game name'' > > > You have a nil object when you didn''t expect it! > > > The error occurred while evaluating nil.name > > > On line #1 of app/views/games/_game.rhtml > > > > > > 1: <%= h game.name %> > > > > > > so the local variable is show up nil. > > > > :collection is something rails uses to render a template multiple > > times. RSpec only renders the file once (as intended). Try using > > :object: > > > > render :partial =>"games/game", :object => @game > > > > (of course, you''ll have to have setup @game). > > > > > > > > > > > On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > > > > > On 10/5/07, Andrew WC Brown < omen.king at gmail.com> wrote: > > > > > 1) > > > > > ''/games/_game.rhtml should show game name'' FAILED > > > > > expected /The Battle for Blaze/, got "" > > > > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > > > > > > > def before > > > > > game_1 = mock_model(Game, > > > > > :name => ''The Battle for Blaze'', > > > > > :salt_grains => 5000000, > > > > > :people => 5000000, > > > > > :days => nil, > > > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > > > :enabled => true) > > > > > game_1.should_receive(:name).and_return("The > Battle > > > for > > > > > Blaze") > > > > > > > > game_1.should_receive(:salt_grains).and_return(5000000) > > > > > > game_1.should_receive(:people).and_return(5000000) > > > > > game_1.should_receive(:days).and_return(nil) > > > > > > game_1.should_receive(:created_at).and_return("Mon > > > Oct > > > > > 01 00:02:44 -0400 2007") > > > > > > game_1.should_receive(:enabled).and_return(true) > > > > > > > > > > game_2 = mock_model(Game, > > > > > :name => ''Epicbattlegrounds'', > > > > > :salt_grains => 30000000, > > > > > :people => 20000000, > > > > > :days => 100, > > > > > :created_at => "Mon Sept 01 12:02:44 -0400 2007", > > > > > :enabled => false) > > > > > > > > > > > > > > game_2.should_receive(:name).and_return("Epicbattlegrounds") > > > > > > > > > > > > > > game_2.should_receive(:salt_grains).and_return(30000000) > > > > > > game_2.should_receive(:people).and_return(20000000) > > > > > game_2.should_receive(:days).and_return(100) > > > > > > game_2.should_receive(:created_at).and_return("Mon > > > Sept > > > > > 01 12:02:44 -0400 2007") > > > > > > game_2.should_receive(:enabled).and_return(false) > > > > > @games = [game_1, game_2] > > > > > assigns[:games] = [game_1, game_2] > > > > > end > > > > > > > > > > it "should show game name" do > > > > > response.should have_text(/The Battle for Blaze/) > > > > > render :partial =>"game", :collection => @games > > > > > > > > Switch these around: > > > > > > > > render :partial =>"game", :collection => @games > > > > response.should have_text(/The Battle for Blaze/) > > > > > > > > > > > > > end > > > > > > > > > > I think the local variable is showing up nil because my specs in the > > > > > index.rhtml were failing when they were fine before and they were > saying > > > > > they didn''t know what this game variable was. > > > > > > > > > > Any ideas? > > > > > > > > > > > > > > > On 10/5/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > > > On 10/5/07, Andrew WC Brown < omen.king at gmail.com> wrote: > > > > > > > I''m trying to spec out a render partial collection but I get the > > > > > following > > > > > > > error > > > > > > > > > > > > > > 2) > > > > > > > NoMethodError in ''/games/_game.rhtml should show game name'' > > > > > > > undefined method `body'' for #<#<Class:0x316580c>:0x2f1154c> > > > > > > > > > > > > > > > > /Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in > > > > > > > `matches?'' > > > > > > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > > > > > > > > > > > def before > > > > > > > game = mock_model(Game, > > > > > > > :name => ''The Battle for Blaze'', > > > > > > > :salt_grains => 5000000, > > > > > > > :people => 5000000, > > > > > > > :days => nil, > > > > > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > > > > > :enabled => true) > > > > > > > game.should_receive(:name).and_return("The Battle for > Blaze") > > > > > > > > > > > > > game.should_receive(:salt_grains).and_return(5000000) > > > > > > > game.should_receive(:people).and_return(5000000) > > > > > > > game.should_receive (:days).and_return(nil) > > > > > > > game.should_receive(:created_at).and_return("Mon Oct 01 > 00:02:44 > > > > > -0400 > > > > > > > 2007") > > > > > > > game.should_receive(:enabled).and_return(true) > > > > > > > > > > > > > > > > > > > > > assigns[:games] = [game] > > > > > > > end > > > > > > > > > > > > > > it "should show game name" do > > > > > > > template.should have_text(/The Battle for Blaze/) > > > > > > > > > > > > response.should have_text .... > > > > > > > > > > > > (not template.should ...) > > > > > > > > > > > > > render :partial =>"game", :collection => @games > > > > > > > end > > > > > > > > > > > > > > _______________________________________________ > > > > > > > rspec-users mailing list > > > > > > > rspec-users at rubyforge.org > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Andrew WC Brown
2007-Oct-06 00:15 UTC
[rspec-users] spec''ing view render partial collection, local variable not found
_game.rhtml_spec require File.dirname(__FILE__) + ''/../../spec_helper'' describe "/games/_game.rhtml" do include GamesHelper before do game = mock_model(Game, :name => ''The Battle for Blaze'', :salt_grains => 5000000, :people => 5000000, :days => nil, :created_at => "Mon Oct 01 00:02:44 -0400 2007", :enabled => true) game.should_receive(:name).and_return(''The Battle for Blaze'') game.should_receive(:salt_grains).and_return(5000000) game.should_receive(:people).and_return(5000000) game.should_receive(:days).and_return(nil) game.should_receive(:created_at).and_return("Mon Oct 01 00:02:44 -0400 2007") game.should_receive(:enabled).and_return(true) @game = game end it "should show game name" do render :partial =>"games/game", :locals => {:game => @game} response.should have_text(/The Battle for Blaze/) end end When you say full listing did you mean html format? I cut out most of my specs just to spec the partial. I only have the one spec in my partial On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote:> > On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote: > > Well I think my biggest problem I was having was the fact that my before > > block was: > > > > def before > > end > > > > instead of > > > > before do > > end > > D''oh - can''t believe I missed that. > > > > > So I think its working, although my mock is complaining now: > > before do > > game = mock_model(Game, > > :name => ''The Battle for Blaze'', > > :salt_grains => 5000000, > > :people => 5000000, > > :days => nil, > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > :enabled => true) > > game.should_receive(:name).and_return(''The Battle for Blaze'') > > game.should_receive (:salt_grains).and_return(5000000) > > game.should_receive(:people).and_return(5000000) > > game.should_receive(:days).and_return(nil) > > game.should_receive(:created_at).and_return("Mon Oct 01 00:02:44 > -0400 > > 2007") > > game.should_receive(:enabled).and_return(true) > > @game = game > > end > > > > 1) > > Spec::Mocks::MockExpectationError in ''/games/_game.rhtml > > should show game name'' > > Mock ''Game_1082'' expected :salt_grains with (any args) once, but > received it > > 0 times > > ./spec/views/games/_game.rhtml_spec.rb:15: > > I''d need to see the full listing of both spec and code as they are now > to help you w/ that. > > > > > > > On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > On 10/5/07, Andrew WC Brown <omen.king at gmail.com > wrote: > > > > Well when I saw that originally thats what I thought the response > was > > > > suppose to come after the render but: > > > > > > > > ActionView::ActionViewError in ''/games/_game.rhtml should show game > > name'' > > > > No rhtml, rxml, rjs or delegate template found for //_game in > > > > /Volumes/EXTERNAL/web/omenking.ca/config/../app/views > > > > > > > > games/_game.rhtml does exist. > > > > > > > > which maybe I have to state: > > > > > > > > it "should show game name" do > > > > render :partial =>"games/game", :collection => @games > > > > response.should have_text(/The Battle for Blaze/) > > > > end > > > > > > > > but then: > > > > > > > > 1) > > > > ActionView::TemplateError in ''/games/_game.rhtml should show game > name'' > > > > You have a nil object when you didn''t expect it! > > > > The error occurred while evaluating nil.name > > > > On line #1 of app/views/games/_game.rhtml > > > > > > > > 1: <%= h game.name %> > > > > > > > > so the local variable is show up nil. > > > > > > :collection is something rails uses to render a template multiple > > > times. RSpec only renders the file once (as intended). Try using > > > :object: > > > > > > render :partial =>"games/game", :object => @game > > > > > > (of course, you''ll have to have setup @game). > > > > > > > > > > > > > > > On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > > > > > > > On 10/5/07, Andrew WC Brown < omen.king at gmail.com> wrote: > > > > > > 1) > > > > > > ''/games/_game.rhtml should show game name'' FAILED > > > > > > expected /The Battle for Blaze/, got "" > > > > > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > > > > > > > > > def before > > > > > > game_1 = mock_model(Game, > > > > > > :name => ''The Battle for Blaze'', > > > > > > :salt_grains => 5000000, > > > > > > :people => 5000000, > > > > > > :days => nil, > > > > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > > > > :enabled => true) > > > > > > game_1.should_receive(:name).and_return("The > > Battle > > > > for > > > > > > Blaze") > > > > > > > > > > game_1.should_receive(:salt_grains).and_return(5000000) > > > > > > > > game_1.should_receive(:people).and_return(5000000) > > > > > > game_1.should_receive(:days).and_return(nil) > > > > > > > > game_1.should_receive(:created_at).and_return("Mon > > > > Oct > > > > > > 01 00:02:44 -0400 2007") > > > > > > > > game_1.should_receive(:enabled).and_return(true) > > > > > > > > > > > > game_2 = mock_model(Game, > > > > > > :name => ''Epicbattlegrounds'', > > > > > > :salt_grains => 30000000, > > > > > > :people => 20000000, > > > > > > :days => 100, > > > > > > :created_at => "Mon Sept 01 12:02:44 -0400 2007", > > > > > > :enabled => false) > > > > > > > > > > > > > > > > > > game_2.should_receive(:name).and_return("Epicbattlegrounds") > > > > > > > > > > > > > > > > > > game_2.should_receive(:salt_grains).and_return(30000000) > > > > > > > > game_2.should_receive(:people).and_return(20000000) > > > > > > game_2.should_receive(:days).and_return(100) > > > > > > > > game_2.should_receive(:created_at).and_return("Mon > > > > Sept > > > > > > 01 12:02:44 -0400 2007") > > > > > > > > game_2.should_receive(:enabled).and_return(false) > > > > > > @games = [game_1, game_2] > > > > > > assigns[:games] = [game_1, game_2] > > > > > > end > > > > > > > > > > > > it "should show game name" do > > > > > > response.should have_text(/The Battle for Blaze/) > > > > > > render :partial =>"game", :collection => @games > > > > > > > > > > Switch these around: > > > > > > > > > > render :partial =>"game", :collection => @games > > > > > response.should have_text(/The Battle for Blaze/) > > > > > > > > > > > > > > > > end > > > > > > > > > > > > I think the local variable is showing up nil because my specs in > the > > > > > > index.rhtml were failing when they were fine before and they > were > > saying > > > > > > they didn''t know what this game variable was. > > > > > > > > > > > > Any ideas? > > > > > > > > > > > > > > > > > > On 10/5/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > > > > On 10/5/07, Andrew WC Brown < omen.king at gmail.com> wrote: > > > > > > > > I''m trying to spec out a render partial collection but I get > the > > > > > > following > > > > > > > > error > > > > > > > > > > > > > > > > 2) > > > > > > > > NoMethodError in ''/games/_game.rhtml should show game name'' > > > > > > > > undefined method `body'' for #<#<Class:0x316580c>:0x2f1154c> > > > > > > > > > > > > > > > > > > > > > /Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in > > > > > > > > `matches?'' > > > > > > > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > > > > > > > > > > > > > def before > > > > > > > > game = mock_model(Game, > > > > > > > > :name => ''The Battle for Blaze'', > > > > > > > > :salt_grains => 5000000, > > > > > > > > :people => 5000000, > > > > > > > > :days => nil, > > > > > > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > > > > > > :enabled => true) > > > > > > > > game.should_receive(:name).and_return("The Battle for > > Blaze") > > > > > > > > > > > > > > > > game.should_receive(:salt_grains).and_return(5000000) > > > > > > > > game.should_receive(:people).and_return(5000000) > > > > > > > > game.should_receive (:days).and_return(nil) > > > > > > > > game.should_receive(:created_at).and_return("Mon Oct 01 > > 00:02:44 > > > > > > -0400 > > > > > > > > 2007") > > > > > > > > game.should_receive(:enabled).and_return(true) > > > > > > > > > > > > > > > > > > > > > > > > assigns[:games] = [game] > > > > > > > > end > > > > > > > > > > > > > > > > it "should show game name" do > > > > > > > > template.should have_text(/The Battle for Blaze/) > > > > > > > > > > > > > > response.should have_text .... > > > > > > > > > > > > > > (not template.should ...) > > > > > > > > > > > > > > > render :partial =>"game", :collection => @games > > > > > > > > end > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > > rspec-users mailing list > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > rspec-users mailing list > > > > > > > rspec-users at rubyforge.org > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Monsterbox Productions putting small businesses on-line 1319 Victoria Avenue East Thunder Bay, Ontario P7C 1C3 Canada Andrew WC Brown web-developer and owner andrew at monsterboxpro.com P: 807-626-9009 F: 807-624-2705 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071005/20da896c/attachment-0001.html
Andrew WC Brown
2007-Oct-06 00:45 UTC
[rspec-users] spec''ing view render partial collection, local variable not found
As soon as I add a second key to the hash it gives me that error before do game = mock_model(Game, :name => ''The Battle for Blaze'', :enabled => ''true'') game.should_receive(:name).and_return(''The Battle for Blaze'') game.should_receive(:enabled).and_return(''true'') @game = game end 1) Spec::Mocks::MockExpectationError in ''/games/_game.rhtml should show game name'' Mock ''Game_1082'' expected :enabled with (any args) once, but received it 0 times ./spec/views/games/_game.rhtml_spec.rb:19: But if it only has name it works fine. ?!??! I have other mock models setup that don''t give me that trouble. On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote:> > _game.rhtml_spec > > require File.dirname(__FILE__) + ''/../../spec_helper'' > > describe "/games/_game.rhtml" do > include GamesHelper > > before do > game = mock_model(Game, > :name => ''The Battle for Blaze'', > :salt_grains => 5000000, > :people => 5000000, > :days => nil, > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > :enabled => true) > game.should_receive (:name).and_return(''The Battle for Blaze'') > game.should_receive(:salt_grains).and_return(5000000) > game.should_receive(:people).and_return(5000000) > game.should_receive(:days).and_return(nil) > game.should_receive(:created_at).and_return("Mon Oct 01 00:02:44 -0400 > 2007") > game.should_receive(:enabled).and_return(true) > > @game = game > end > > it "should show game name" do > render :partial =>"games/game", :locals => {:game => @game} > response.should have_text(/The Battle for Blaze/) > end > > end > > When you say full listing did you mean html format? > I cut out most of my specs just to spec the partial. > I only have the one spec in my partial > > > > On 10/5/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > On 10/5/07, Andrew WC Brown < omen.king at gmail.com> wrote: > > > Well I think my biggest problem I was having was the fact that my > > before > > > block was: > > > > > > def before > > > end > > > > > > instead of > > > > > > before do > > > end > > > > D''oh - can''t believe I missed that. > > > > > > > > So I think its working, although my mock is complaining now: > > > before do > > > game = mock_model(Game, > > > :name => ''The Battle for Blaze'', > > > :salt_grains => 5000000, > > > :people => 5000000, > > > :days => nil, > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > :enabled => true) > > > game.should_receive(:name).and_return(''The Battle for Blaze'') > > > game.should_receive (:salt_grains).and_return(5000000) > > > game.should_receive(:people).and_return(5000000) > > > game.should_receive(:days).and_return(nil) > > > game.should_receive(:created_at).and_return("Mon Oct 01 00:02:44 > > -0400 > > > 2007") > > > game.should_receive(:enabled).and_return(true) > > > @game = game > > > end > > > > > > 1) > > > Spec::Mocks::MockExpectationError in ''/games/_game.rhtml > > > should show game name'' > > > Mock ''Game_1082'' expected :salt_grains with (any args) once, but > > received it > > > 0 times > > > ./spec/views/games/_game.rhtml_spec.rb:15: > > > > I''d need to see the full listing of both spec and code as they are now > > to help you w/ that. > > > > > > > > > > > On 10/5/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > On 10/5/07, Andrew WC Brown <omen.king at gmail.com > wrote: > > > > > Well when I saw that originally thats what I thought the response > > was > > > > > suppose to come after the render but: > > > > > > > > > > ActionView::ActionViewError in ''/games/_game.rhtml should show > > game > > > name'' > > > > > No rhtml, rxml, rjs or delegate template found for //_game in > > > > > /Volumes/EXTERNAL/web/omenking.ca/config/../app/views > > > > > > > > > > games/_game.rhtml does exist. > > > > > > > > > > which maybe I have to state: > > > > > > > > > > it "should show game name" do > > > > > render :partial =>"games/game", :collection => @games > > > > > response.should have_text(/The Battle for Blaze/) > > > > > end > > > > > > > > > > but then: > > > > > > > > > > 1) > > > > > ActionView::TemplateError in ''/games/_game.rhtml should show game > > name'' > > > > > You have a nil object when you didn''t expect it! > > > > > The error occurred while evaluating nil.name > > > > > On line #1 of app/views/games/_game.rhtml > > > > > > > > > > 1: <%= h game.name %> > > > > > > > > > > so the local variable is show up nil. > > > > > > > > :collection is something rails uses to render a template multiple > > > > times. RSpec only renders the file once (as intended). Try using > > > > :object: > > > > > > > > render :partial =>"games/game", :object => @game > > > > > > > > (of course, you''ll have to have setup @game). > > > > > > > > > > > > > > > > > > > On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > > > > > > > > > On 10/5/07, Andrew WC Brown < omen.king at gmail.com> wrote: > > > > > > > 1) > > > > > > > ''/games/_game.rhtml should show game name'' FAILED > > > > > > > expected /The Battle for Blaze/, got "" > > > > > > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > > > > > > > > > > > def before > > > > > > > game_1 = mock_model(Game, > > > > > > > :name => ''The Battle for Blaze'', > > > > > > > :salt_grains => 5000000, > > > > > > > :people => 5000000, > > > > > > > :days => nil, > > > > > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > > > > > :enabled => true) > > > > > > > game_1.should_receive(:name).and_return("The > > > Battle > > > > > for > > > > > > > Blaze") > > > > > > > > > > > > game_1.should_receive(:salt_grains).and_return(5000000) > > > > > > > > > > game_1.should_receive(:people).and_return(5000000) > > > > > > > game_1.should_receive(:days).and_return(nil) > > > > > > > > > > game_1.should_receive(:created_at).and_return("Mon > > > > > Oct > > > > > > > 01 00:02:44 -0400 2007") > > > > > > > > > > game_1.should_receive(:enabled).and_return(true) > > > > > > > > > > > > > > game_2 = mock_model(Game, > > > > > > > :name => ''Epicbattlegrounds'', > > > > > > > :salt_grains => 30000000, > > > > > > > :people => 20000000, > > > > > > > :days => 100, > > > > > > > :created_at => "Mon Sept 01 12:02:44 -0400 2007", > > > > > > > :enabled => false) > > > > > > > > > > > > > > > > > > > > > > game_2.should_receive(:name).and_return("Epicbattlegrounds") > > > > > > > > > > > > > > > > > > > > > > game_2.should_receive(:salt_grains).and_return(30000000) > > > > > > > > > > game_2.should_receive(:people).and_return(20000000) > > > > > > > game_2.should_receive(:days).and_return(100) > > > > > > > > > > game_2.should_receive(:created_at).and_return("Mon > > > > > Sept > > > > > > > 01 12:02:44 -0400 2007") > > > > > > > > > > game_2.should_receive(:enabled).and_return(false) > > > > > > > @games = [game_1, game_2] > > > > > > > assigns[:games] = [game_1, game_2] > > > > > > > end > > > > > > > > > > > > > > it "should show game name" do > > > > > > > response.should have_text(/The Battle for Blaze/) > > > > > > > render :partial =>"game", :collection => @games > > > > > > > > > > > > Switch these around: > > > > > > > > > > > > render :partial =>"game", :collection => @games > > > > > > response.should have_text(/The Battle for Blaze/) > > > > > > > > > > > > > > > > > > > end > > > > > > > > > > > > > > I think the local variable is showing up nil because my specs > > in the > > > > > > > index.rhtml were failing when they were fine before and they > > were > > > saying > > > > > > > they didn''t know what this game variable was. > > > > > > > > > > > > > > Any ideas? > > > > > > > > > > > > > > > > > > > > > On 10/5/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > > > > > On 10/5/07, Andrew WC Brown < omen.king at gmail.com> wrote: > > > > > > > > > I''m trying to spec out a render partial collection but I > > get the > > > > > > > following > > > > > > > > > error > > > > > > > > > > > > > > > > > > 2) > > > > > > > > > NoMethodError in ''/games/_game.rhtml should show game > > name'' > > > > > > > > > undefined method `body'' for > > #<#<Class:0x316580c>:0x2f1154c> > > > > > > > > > > > > > > > > > > > > > > > > > > /Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in > > > > > > > > > > > `matches?'' > > > > > > > > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > > > > > > > > > > > > > > > def before > > > > > > > > > game = mock_model(Game, > > > > > > > > > :name => ''The Battle for Blaze'', > > > > > > > > > :salt_grains => 5000000, > > > > > > > > > :people => 5000000, > > > > > > > > > :days => nil, > > > > > > > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > > > > > > > :enabled => true) > > > > > > > > > game.should_receive(:name).and_return("The Battle for > > > Blaze") > > > > > > > > > > > > > > > > > > > game.should_receive(:salt_grains).and_return(5000000) > > > > > > > > > game.should_receive(:people).and_return(5000000) > > > > > > > > > game.should_receive (:days).and_return(nil) > > > > > > > > > game.should_receive(:created_at).and_return("Mon Oct > > 01 > > > 00:02:44 > > > > > > > -0400 > > > > > > > > > 2007") > > > > > > > > > game.should_receive(:enabled).and_return(true) > > > > > > > > > > > > > > > > > > > > > > > > > > > assigns[:games] = [game] > > > > > > > > > end > > > > > > > > > > > > > > > > > > it "should show game name" do > > > > > > > > > template.should have_text(/The Battle for Blaze/) > > > > > > > > > > > > > > > > response.should have_text .... > > > > > > > > > > > > > > > > (not template.should ...) > > > > > > > > > > > > > > > > > render :partial =>"game", :collection => @games > > > > > > > > > end > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > > > rspec-users mailing list > > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > > rspec-users mailing list > > > > > > > > rspec-users at rubyforge.org > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > rspec-users mailing list > > > > > > > rspec-users at rubyforge.org > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > Monsterbox Productions > putting small businesses on-line > > 1319 Victoria Avenue East > Thunder Bay, Ontario P7C 1C3 > Canada > > Andrew WC Brown > web-developer and owner > andrew at monsterboxpro.com > P: 807-626-9009 > F: 807-624-2705-- Monsterbox Productions putting small businesses on-line 1319 Victoria Avenue East Thunder Bay, Ontario P7C 1C3 Canada Andrew WC Brown web-developer and owner andrew at monsterboxpro.com P: 807-626-9009 F: 807-624-2705 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071005/39d51da6/attachment-0001.html
David Chelimsky
2007-Oct-06 01:01 UTC
[rspec-users] spec''ing view render partial collection, local variable not found
I meant the view code as well. On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote:> As soon as I add a second key to the hash it gives me that error > > before do > game = mock_model(Game, :name => ''The Battle for Blaze'', :enabled => > ''true'') > game.should_receive(:name).and_return(''The Battle for Blaze'') > game.should_receive(:enabled).and_return(''true'') > > @game = game > end > > 1) > Spec::Mocks::MockExpectationError in ''/games/_game.rhtml > should show game name'' > Mock ''Game_1082'' expected :enabled with (any args) once, but received it 0 > times > ./spec/views/games/_game.rhtml_spec.rb:19: > > But if it only has name it works fine. > > ?!??! I have other mock models setup that don''t give me that trouble. > > > > On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote: > > _game.rhtml_spec > > > > require File.dirname(__FILE__) + ''/../../spec_helper'' > > > > describe "/games/_game.rhtml" do > > include GamesHelper > > > > before do > > game = mock_model(Game, > > :name => ''The Battle for Blaze'', > > :salt_grains => 5000000, > > :people => 5000000, > > :days => nil, > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > :enabled => true) > > game.should_receive (:name).and_return(''The Battle for Blaze'') > > game.should_receive(:salt_grains).and_return(5000000) > > game.should_receive(:people).and_return(5000000) > > game.should_receive(:days).and_return(nil) > > game.should_receive(:created_at).and_return("Mon Oct 01 00:02:44 -0400 > 2007") > > game.should_receive(:enabled).and_return(true) > > > > @game = game > > end > > > > it "should show game name" do > > render :partial =>"games/game", :locals => {:game => @game} > > response.should have_text(/The Battle for Blaze/) > > end > > > > end > > > > When you say full listing did you mean html format? > > I cut out most of my specs just to spec the partial. > > I only have the one spec in my partial > > > > > > > > > > > > On 10/5/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > On 10/5/07, Andrew WC Brown < omen.king at gmail.com> wrote: > > > > Well I think my biggest problem I was having was the fact that my > before > > > > block was: > > > > > > > > def before > > > > end > > > > > > > > instead of > > > > > > > > before do > > > > end > > > > > > D''oh - can''t believe I missed that. > > > > > > > > > > > So I think its working, although my mock is complaining now: > > > > before do > > > > game = mock_model(Game, > > > > :name => ''The Battle for Blaze'', > > > > :salt_grains => 5000000, > > > > :people => 5000000, > > > > :days => nil, > > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > > :enabled => true) > > > > game.should_receive(:name).and_return(''The Battle for Blaze'') > > > > game.should_receive > (:salt_grains).and_return(5000000) > > > > game.should_receive(:people).and_return(5000000) > > > > game.should_receive(:days).and_return(nil) > > > > game.should_receive(:created_at).and_return("Mon Oct 01 00:02:44 > -0400 > > > > 2007") > > > > game.should_receive(:enabled).and_return(true) > > > > @game = game > > > > end > > > > > > > > 1) > > > > Spec::Mocks::MockExpectationError in > ''/games/_game.rhtml > > > > should show game name'' > > > > Mock ''Game_1082'' expected :salt_grains with (any args) once, but > received it > > > > 0 times > > > > ./spec/views/games/_game.rhtml_spec.rb:15: > > > > > > I''d need to see the full listing of both spec and code as they are now > > > to help you w/ that. > > > > > > > > > > > > > > > On 10/5/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > > On 10/5/07, Andrew WC Brown < omen.king at gmail.com > wrote: > > > > > > Well when I saw that originally thats what I thought the response > was > > > > > > suppose to come after the render but: > > > > > > > > > > > > ActionView::ActionViewError in ''/games/_game.rhtml should show > game > > > > name'' > > > > > > No rhtml, rxml, rjs or delegate template found for //_game in > > > > > > > /Volumes/EXTERNAL/web/omenking.ca/config/../app/views > > > > > > > > > > > > games/_game.rhtml does exist. > > > > > > > > > > > > which maybe I have to state: > > > > > > > > > > > > it "should show game name" do > > > > > > render :partial =>"games/game", :collection => @games > > > > > > response.should have_text(/The Battle for Blaze/) > > > > > > end > > > > > > > > > > > > but then: > > > > > > > > > > > > 1) > > > > > > ActionView::TemplateError in ''/games/_game.rhtml should show game > name'' > > > > > > You have a nil object when you didn''t expect it! > > > > > > The error occurred while evaluating nil.name > > > > > > On line #1 of app/views/games/_game.rhtml > > > > > > > > > > > > 1: <%= h game.name %> > > > > > > > > > > > > so the local variable is show up nil. > > > > > > > > > > :collection is something rails uses to render a template multiple > > > > > times. RSpec only renders the file once (as intended). Try using > > > > > :object: > > > > > > > > > > render :partial =>"games/game", :object => @game > > > > > > > > > > (of course, you''ll have to have setup @game). > > > > > > > > > > > > > > > > > > > > > > > On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > > > > > > > > > > > On 10/5/07, Andrew WC Brown < omen.king at gmail.com> wrote: > > > > > > > > 1) > > > > > > > > ''/games/_game.rhtml should show game name'' FAILED > > > > > > > > expected /The Battle for Blaze/, got "" > > > > > > > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > > > > > > > > > > > > > def before > > > > > > > > game_1 = mock_model(Game, > > > > > > > > :name => ''The Battle for Blaze'', > > > > > > > > :salt_grains => 5000000, > > > > > > > > :people => 5000000, > > > > > > > > :days => nil, > > > > > > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > > > > > > :enabled => true) > > > > > > > > > game_1.should_receive(:name).and_return("The > > > > Battle > > > > > > for > > > > > > > > Blaze") > > > > > > > > > > > > > > > game_1.should_receive(:salt_grains).and_return(5000000) > > > > > > > > > > > > game_1.should_receive(:people).and_return(5000000) > > > > > > > > > game_1.should_receive(:days).and_return(nil) > > > > > > > > > > > > game_1.should_receive(:created_at).and_return("Mon > > > > > > Oct > > > > > > > > 01 00:02:44 -0400 2007") > > > > > > > > > > > > game_1.should_receive(:enabled).and_return(true) > > > > > > > > > > > > > > > > game_2 = mock_model(Game, > > > > > > > > :name => ''Epicbattlegrounds'', > > > > > > > > :salt_grains => 30000000, > > > > > > > > :people => 20000000, > > > > > > > > :days => 100, > > > > > > > > :created_at => "Mon Sept 01 12:02:44 -0400 2007", > > > > > > > > :enabled => false) > > > > > > > > > > > > > > > > > > > > > > > > > > > game_2.should_receive(:name).and_return("Epicbattlegrounds") > > > > > > > > > > > > > > > > > > > > > > > > > > > game_2.should_receive(:salt_grains).and_return(30000000) > > > > > > > > > > > > game_2.should_receive(:people).and_return(20000000) > > > > > > > > > game_2.should_receive(:days).and_return(100) > > > > > > > > > > > > game_2.should_receive(:created_at).and_return("Mon > > > > > > Sept > > > > > > > > 01 12:02:44 -0400 2007") > > > > > > > > > > > > game_2.should_receive(:enabled).and_return(false) > > > > > > > > @games = [game_1, game_2] > > > > > > > > assigns[:games] = [game_1, game_2] > > > > > > > > end > > > > > > > > > > > > > > > > it "should show game name" do > > > > > > > > response.should have_text(/The Battle for Blaze/) > > > > > > > > render :partial =>"game", :collection => @games > > > > > > > > > > > > > > Switch these around: > > > > > > > > > > > > > > render :partial =>"game", :collection => @games > > > > > > > response.should have_text(/The Battle for Blaze/) > > > > > > > > > > > > > > > > > > > > > > end > > > > > > > > > > > > > > > > I think the local variable is showing up nil because my specs > in the > > > > > > > > index.rhtml were failing when they were fine before and they > were > > > > saying > > > > > > > > they didn''t know what this game variable was. > > > > > > > > > > > > > > > > Any ideas? > > > > > > > > > > > > > > > > > > > > > > > > On 10/5/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > > > > > > On 10/5/07, Andrew WC Brown < omen.king at gmail.com> wrote: > > > > > > > > > > I''m trying to spec out a render partial collection but I > get the > > > > > > > > following > > > > > > > > > > error > > > > > > > > > > > > > > > > > > > > 2) > > > > > > > > > > NoMethodError in ''/games/_game.rhtml should show game > name'' > > > > > > > > > > undefined method `body'' for > #<#<Class:0x316580c>:0x2f1154c> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > /Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in > > > > > > > > > > `matches?'' > > > > > > > > > > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > > > > > > > > > > > > > > > > > def before > > > > > > > > > > game = mock_model(Game, > > > > > > > > > > :name => ''The Battle for Blaze'', > > > > > > > > > > :salt_grains => 5000000, > > > > > > > > > > :people => 5000000, > > > > > > > > > > :days => nil, > > > > > > > > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > > > > > > > > :enabled => true) > > > > > > > > > > game.should_receive(:name).and_return("The Battle for > > > > Blaze") > > > > > > > > > > > > > > > > > > > > > > game.should_receive(:salt_grains).and_return(5000000) > > > > > > > > > > game.should_receive(:people).and_return(5000000) > > > > > > > > > > game.should_receive (:days).and_return(nil) > > > > > > > > > > game.should_receive(:created_at).and_return("Mon Oct > 01 > > > > 00:02:44 > > > > > > > > -0400 > > > > > > > > > > 2007") > > > > > > > > > > game.should_receive(:enabled).and_return(true) > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > assigns[:games] = [game] > > > > > > > > > > end > > > > > > > > > > > > > > > > > > > > it "should show game name" do > > > > > > > > > > template.should have_text(/The Battle for Blaze/) > > > > > > > > > > > > > > > > > > response.should have_text .... > > > > > > > > > > > > > > > > > > (not template.should ...) > > > > > > > > > > > > > > > > > > > render :partial =>"game", :collection => @games > > > > > > > > > > end > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > > > > rspec-users mailing list > > > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > > > rspec-users mailing list > > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > > rspec-users mailing list > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > rspec-users mailing list > > > > > > > rspec-users at rubyforge.org > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > -- > > Monsterbox Productions > > putting small businesses on-line > > > > 1319 Victoria Avenue East > > Thunder Bay, Ontario P7C 1C3 > > Canada > > > > Andrew WC Brown > > web-developer and owner > > andrew at monsterboxpro.com > > P: 807-626-9009 > > F: 807-624-2705 > > > > -- > Monsterbox Productions > putting small businesses on-line > > 1319 Victoria Avenue East > Thunder Bay, Ontario P7C 1C3 > Canada > > Andrew WC Brown > web-developer and owner > andrew at monsterboxpro.com > P: 807-626-9009 > F: 807-624-2705 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Andrew WC Brown
2007-Oct-06 01:11 UTC
[rspec-users] spec''ing view render partial collection, local variable not found
I outputted name and enabled to see if it the mock object was working. before do game = mock_model(Game, :name => ''The Battle for Blaze'', :enabled => ''true'') puts game.name puts game.enabled game.should_receive(:name).and_return(''The Battle for Blaze'') game.should_receive(:enabled).and_return(''true'') @game = game end I still got the error but I saw in the print out ''The Battle for Blaze'' and ''True'' So I for some reason thought that if I write unknowingly in my partial <%= h game.enabled %> it might pass and it did. I was thinking that game.should_recieve was test that the mock model being made received Battle for the Blaze like I was confirming that the the model was correct. But then I looked at the code and really thought about it and realized that what it was saying that the Game model was expecting name to be called at some point during that spec and since it hadn''t been in the partial such as game.name then it would fail. When I''m working with RSpec I sometimes forget what actually is going on and I interpret how things are happening in a different way. For that pragmatic book will it cover things such as: how to spec a rendered template how to spec a rendered partial how to spec a rendered partial collection how to spec a cookie ... or will it be more of a guide like the RSpec Peepcode videos but in book format with more elaboration. I don''t think I would have ever spec''d view if I hadn''t started using story runner. I love that story runner. On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote:> > I meant the view code as well. > > On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote: > > As soon as I add a second key to the hash it gives me that error > > > > before do > > game = mock_model(Game, :name => ''The Battle for Blaze'', :enabled => > > ''true'') > > game.should_receive(:name).and_return(''The Battle for Blaze'') > > game.should_receive(:enabled).and_return(''true'') > > > > @game = game > > end > > > > 1) > > Spec::Mocks::MockExpectationError in ''/games/_game.rhtml > > should show game name'' > > Mock ''Game_1082'' expected :enabled with (any args) once, but received it > 0 > > times > > ./spec/views/games/_game.rhtml_spec.rb:19: > > > > But if it only has name it works fine. > > > > ?!??! I have other mock models setup that don''t give me that trouble. > > > > > > > > On 10/5/07, Andrew WC Brown <omen.king at gmail.com> wrote: > > > _game.rhtml_spec > > > > > > require File.dirname(__FILE__) + ''/../../spec_helper'' > > > > > > describe "/games/_game.rhtml" do > > > include GamesHelper > > > > > > before do > > > game = mock_model(Game, > > > :name => ''The Battle for Blaze'', > > > :salt_grains => 5000000, > > > :people => 5000000, > > > :days => nil, > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > :enabled => true) > > > game.should_receive (:name).and_return(''The Battle for Blaze'') > > > game.should_receive(:salt_grains).and_return(5000000) > > > game.should_receive(:people).and_return(5000000) > > > game.should_receive(:days).and_return(nil) > > > game.should_receive(:created_at).and_return("Mon Oct 01 00:02:44 > -0400 > > 2007") > > > game.should_receive(:enabled).and_return(true) > > > > > > @game = game > > > end > > > > > > it "should show game name" do > > > render :partial =>"games/game", :locals => {:game => @game} > > > response.should have_text(/The Battle for Blaze/) > > > end > > > > > > end > > > > > > When you say full listing did you mean html format? > > > I cut out most of my specs just to spec the partial. > > > I only have the one spec in my partial > > > > > > > > > > > > > > > > > > On 10/5/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > On 10/5/07, Andrew WC Brown < omen.king at gmail.com> wrote: > > > > > Well I think my biggest problem I was having was the fact that my > > before > > > > > block was: > > > > > > > > > > def before > > > > > end > > > > > > > > > > instead of > > > > > > > > > > before do > > > > > end > > > > > > > > D''oh - can''t believe I missed that. > > > > > > > > > > > > > > So I think its working, although my mock is complaining now: > > > > > before do > > > > > game = mock_model(Game, > > > > > :name => ''The Battle for Blaze'', > > > > > :salt_grains => 5000000, > > > > > :people => 5000000, > > > > > :days => nil, > > > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > > > :enabled => true) > > > > > game.should_receive(:name).and_return(''The Battle for Blaze'') > > > > > game.should_receive > > (:salt_grains).and_return(5000000) > > > > > game.should_receive(:people).and_return(5000000) > > > > > game.should_receive(:days).and_return(nil) > > > > > game.should_receive(:created_at).and_return("Mon Oct 01 > 00:02:44 > > -0400 > > > > > 2007") > > > > > game.should_receive(:enabled).and_return(true) > > > > > @game = game > > > > > end > > > > > > > > > > 1) > > > > > Spec::Mocks::MockExpectationError in > > ''/games/_game.rhtml > > > > > should show game name'' > > > > > Mock ''Game_1082'' expected :salt_grains with (any args) once, but > > received it > > > > > 0 times > > > > > ./spec/views/games/_game.rhtml_spec.rb:15: > > > > > > > > I''d need to see the full listing of both spec and code as they are > now > > > > to help you w/ that. > > > > > > > > > > > > > > > > > > > On 10/5/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > > > On 10/5/07, Andrew WC Brown < omen.king at gmail.com > wrote: > > > > > > > Well when I saw that originally thats what I thought the > response > > was > > > > > > > suppose to come after the render but: > > > > > > > > > > > > > > ActionView::ActionViewError in ''/games/_game.rhtml should show > > game > > > > > name'' > > > > > > > No rhtml, rxml, rjs or delegate template found for //_game in > > > > > > > > > /Volumes/EXTERNAL/web/omenking.ca/config/../app/views > > > > > > > > > > > > > > games/_game.rhtml does exist. > > > > > > > > > > > > > > which maybe I have to state: > > > > > > > > > > > > > > it "should show game name" do > > > > > > > render :partial =>"games/game", :collection => @games > > > > > > > response.should have_text(/The Battle for Blaze/) > > > > > > > end > > > > > > > > > > > > > > but then: > > > > > > > > > > > > > > 1) > > > > > > > ActionView::TemplateError in ''/games/_game.rhtml should show > game > > name'' > > > > > > > You have a nil object when you didn''t expect it! > > > > > > > The error occurred while evaluating nil.name > > > > > > > On line #1 of app/views/games/_game.rhtml > > > > > > > > > > > > > > 1: <%= h game.name %> > > > > > > > > > > > > > > so the local variable is show up nil. > > > > > > > > > > > > :collection is something rails uses to render a template > multiple > > > > > > times. RSpec only renders the file once (as intended). Try using > > > > > > :object: > > > > > > > > > > > > render :partial =>"games/game", :object => @game > > > > > > > > > > > > (of course, you''ll have to have setup @game). > > > > > > > > > > > > > > > > > > > > > > > > > > > On 10/5/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > > > > > > > > > > > > > On 10/5/07, Andrew WC Brown < omen.king at gmail.com> wrote: > > > > > > > > > 1) > > > > > > > > > ''/games/_game.rhtml should show game name'' FAILED > > > > > > > > > expected /The Battle for Blaze/, got "" > > > > > > > > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > > > > > > > > > > > > > > > def before > > > > > > > > > game_1 = mock_model(Game, > > > > > > > > > :name => ''The Battle for Blaze'', > > > > > > > > > :salt_grains => 5000000, > > > > > > > > > :people => 5000000, > > > > > > > > > :days => nil, > > > > > > > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > > > > > > > :enabled => true) > > > > > > > > > > > game_1.should_receive(:name).and_return("The > > > > > Battle > > > > > > > for > > > > > > > > > Blaze") > > > > > > > > > > > > > > > > > > game_1.should_receive(:salt_grains).and_return(5000000) > > > > > > > > > > > > > > game_1.should_receive(:people).and_return(5000000) > > > > > > > > > > > game_1.should_receive(:days).and_return(nil) > > > > > > > > > > > > > > game_1.should_receive(:created_at).and_return("Mon > > > > > > > Oct > > > > > > > > > 01 00:02:44 -0400 2007") > > > > > > > > > > > > > > game_1.should_receive(:enabled).and_return(true) > > > > > > > > > > > > > > > > > > game_2 = mock_model(Game, > > > > > > > > > :name => ''Epicbattlegrounds'', > > > > > > > > > :salt_grains => 30000000, > > > > > > > > > :people => 20000000, > > > > > > > > > :days => 100, > > > > > > > > > :created_at => "Mon Sept 01 12:02:44 -0400 2007", > > > > > > > > > :enabled => false) > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > game_2.should_receive(:name).and_return("Epicbattlegrounds") > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > game_2.should_receive(:salt_grains).and_return(30000000) > > > > > > > > > > > > > > game_2.should_receive(:people).and_return(20000000) > > > > > > > > > > > game_2.should_receive(:days).and_return(100) > > > > > > > > > > > > > > game_2.should_receive(:created_at).and_return("Mon > > > > > > > Sept > > > > > > > > > 01 12:02:44 -0400 2007") > > > > > > > > > > > > > > game_2.should_receive(:enabled).and_return(false) > > > > > > > > > @games = [game_1, game_2] > > > > > > > > > assigns[:games] = [game_1, game_2] > > > > > > > > > end > > > > > > > > > > > > > > > > > > it "should show game name" do > > > > > > > > > response.should have_text(/The Battle for Blaze/) > > > > > > > > > render :partial =>"game", :collection => @games > > > > > > > > > > > > > > > > Switch these around: > > > > > > > > > > > > > > > > render :partial =>"game", :collection => @games > > > > > > > > response.should have_text(/The Battle for Blaze/) > > > > > > > > > > > > > > > > > > > > > > > > > end > > > > > > > > > > > > > > > > > > I think the local variable is showing up nil because my > specs > > in the > > > > > > > > > index.rhtml were failing when they were fine before and > they > > were > > > > > saying > > > > > > > > > they didn''t know what this game variable was. > > > > > > > > > > > > > > > > > > Any ideas? > > > > > > > > > > > > > > > > > > > > > > > > > > > On 10/5/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > > > > > > > On 10/5/07, Andrew WC Brown < omen.king at gmail.com> > wrote: > > > > > > > > > > > I''m trying to spec out a render partial collection but > I > > get the > > > > > > > > > following > > > > > > > > > > > error > > > > > > > > > > > > > > > > > > > > > > 2) > > > > > > > > > > > NoMethodError in ''/games/_game.rhtml should show game > > name'' > > > > > > > > > > > undefined method `body'' for > > #<#<Class:0x316580c>:0x2f1154c> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > /Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in > > > > > > > > > > > `matches?'' > > > > > > > > > > > > > ./spec/views/games/_game.rhtml_spec.rb:39: > > > > > > > > > > > > > > > > > > > > > > def before > > > > > > > > > > > game = mock_model(Game, > > > > > > > > > > > :name => ''The Battle for Blaze'', > > > > > > > > > > > :salt_grains => 5000000, > > > > > > > > > > > :people => 5000000, > > > > > > > > > > > :days => nil, > > > > > > > > > > > :created_at => "Mon Oct 01 00:02:44 -0400 2007", > > > > > > > > > > > :enabled => true) > > > > > > > > > > > game.should_receive(:name).and_return("The Battle > for > > > > > Blaze") > > > > > > > > > > > > > > > > > > > > > > > > > game.should_receive(:salt_grains).and_return(5000000) > > > > > > > > > > > game.should_receive(:people).and_return(5000000) > > > > > > > > > > > game.should_receive (:days).and_return(nil) > > > > > > > > > > > game.should_receive(:created_at).and_return("Mon > Oct > > 01 > > > > > 00:02:44 > > > > > > > > > -0400 > > > > > > > > > > > 2007") > > > > > > > > > > > game.should_receive(:enabled).and_return(true) > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > assigns[:games] = [game] > > > > > > > > > > > end > > > > > > > > > > > > > > > > > > > > > > it "should show game name" do > > > > > > > > > > > template.should have_text(/The Battle for Blaze/) > > > > > > > > > > > > > > > > > > > > response.should have_text .... > > > > > > > > > > > > > > > > > > > > (not template.should ...) > > > > > > > > > > > > > > > > > > > > > render :partial =>"game", :collection => @games > > > > > > > > > > > end > > > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > > > > > rspec-users mailing list > > > > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > > > > rspec-users mailing list > > > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > > > rspec-users mailing list > > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > > rspec-users mailing list > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > rspec-users mailing list > > > > > > > rspec-users at rubyforge.org > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > -- > > > Monsterbox Productions > > > putting small businesses on-line > > > > > > 1319 Victoria Avenue East > > > Thunder Bay, Ontario P7C 1C3 > > > Canada > > > > > > Andrew WC Brown > > > web-developer and owner > > > andrew at monsterboxpro.com > > > P: 807-626-9009 > > > F: 807-624-2705 > > > > > > > > -- > > Monsterbox Productions > > putting small businesses on-line > > > > 1319 Victoria Avenue East > > Thunder Bay, Ontario P7C 1C3 > > Canada > > > > Andrew WC Brown > > web-developer and owner > > andrew at monsterboxpro.com > > P: 807-626-9009 > > F: 807-624-2705 > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Monsterbox Productions putting small businesses on-line 1319 Victoria Avenue East Thunder Bay, Ontario P7C 1C3 Canada Andrew WC Brown web-developer and owner andrew at monsterboxpro.com P: 807-626-9009 F: 807-624-2705 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071005/0c5aeeff/attachment-0001.html
Andrew WC Brown
2007-Oct-06 01:30 UTC
[rspec-users] spec''ing view render partial collection, local variable not found
before do game = mock_model(Game, :name => ''The Battle for Blaze'', :enabled => ''true'') puts game.name puts game.enabled game.should_receive(:name).and_return(''The Battle for Blaze'') game.should_receive(:enabled).and_return(''true'') @game = game end I still got the error but I saw in the print out ''The Battle for Blaze'' and ''True'' So I for some reason thought that if I write unknowingly in my partial <%= h game.enabled %> it might pass and it did. I was thinking that game.should_recieve was test that the mock model being made received Battle for the Blaze like I was confirming that the the model was correct. But then I looked at the code and really thought about it and realized that what it was saying that the Game model was expecting name to be called at some point during that spec and since it hadn''t been in the partial such as game.name then it would fail. When I''m working with RSpec I sometimes forget what actually is going on and I interpret how things are happening in a different way. For that pragmatic book will it cover things such as: how to spec a rendered template how to spec a rendered partial how to spec a rendered partial collection how to spec a cookie ... or will it be more of a guide like the RSpec Peepcode videos but in book format with more elaboration. I don''t think I would have ever spec''d view if I hadn''t started using story runner. I love that story runner. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071005/08b7aec7/attachment.html