Hello Everyone, Why is my controller test in the get method not working? github.com/haloflightleader/bank/blob/02695c7c5106b30e178d3a0d05125f8deedd5e67/spec/controllers/accounts_controller_spec.rb#L18 This is practically a copy from the rails guides and it works in my index test. The render test works... it''s only the assigns portion that refuses to work. I''m studying Rails, but am focusing on rspec because Rails by itself is easy and I feel that I don''t want to write anything without rspec being right next to it, even if I have to write the tests after. I have gone through several tutorials already: Michael Hartl''s, Pragmatic Studio, and Code School. So now, I just need to do it and gain proficiency. Thank you. p -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit groups.google.com/d/msgid/rubyonrails-talk/54f7c3f5-28b8-48ee-aea0-1f885edafcd5@googlegroups.com. For more options, visit groups.google.com/groups/opt_out.
Peter
2013-Nov-17 07:50 UTC
Re: why is my rspec controller test for get method not working?
github.com/haloflightleader/bank/commit/88762271b5feda1390054b472cfb1de006c2b5da I corrected my code, but am still getting this:> Failures: > 1) AccountsController Get new assigned @account > Failure/Error: expect( assigns(:account) ).to eq( [account] ) > > expected: [#<Account id: nil, name: nil, description: nil, > account_number: nil, created_at: nil, updated_at: nil>] > got: #<Account id: nil, name: nil, description: nil, > account_number: nil, created_at: nil, updated_at: nil> > > (compared using ==) > > Diff: > @@ -1,2 +1,2 @@ > -[#<Account id: nil, name: nil, description: nil, account_number: > nil, created_at: nil, updated_at: nil>] > +#<Account id: nil, name: nil, description: nil, account_number: > nil, created_at: nil, updated_at: nil> > > # ./spec/controllers/accounts_controller_spec.rb:21:in `block (3 > levels) in <top (required)>'' > Finished in 0.13115 seconds > 18 examples, 1 failure > Failed examples: > rspec ./spec/controllers/accounts_controller_spec.rb:18 # > AccountsController Get new assigned @account > Randomized with seed 52138On Saturday, November 16, 2013 10:08:48 PM UTC-8, Peter wrote:> > Hello Everyone, > > Why is my controller test in the get method not working? > > github.com/haloflightleader/bank/blob/02695c7c5106b30e178d3a0d05125f8deedd5e67/spec/controllers/accounts_controller_spec.rb#L18 > > This is practically a copy from the rails guides and it works in my index > test. The render test works... it''s only the assigns portion that refuses > to work. > > I''m studying Rails, but am focusing on rspec because Rails by itself is > easy and I feel that I don''t want to write anything without rspec being > right next to it, even if I have to write the tests after. I have gone > through several tutorials already: > Michael Hartl''s, Pragmatic Studio, and Code School. > > So now, I just need to do it and gain proficiency. Thank you. > > p > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit groups.google.com/d/msgid/rubyonrails-talk/ba9d2bcc-0b33-4466-9bfa-f85b69fa4b84@googlegroups.com. For more options, visit groups.google.com/groups/opt_out.
Josh Jordan
2013-Nov-17 14:59 UTC
Re: why is my rspec controller test for get method not working?
I would have to contest that you didn''t quite correct it then, eh? :p You wrote an expectation that says "I expect @account to be an array of accounts that contains a single, specific instance of Account." Why are you looking for an array? Your controller code looks right - it assigns @account to be a new instance Account. So you, you have two problems here. The one I described you can illustrate this way: expected = [account] puts "Expected class: #{expected.class}" puts "Actual class: #{assigns(:account).class}" expect( assigns(:account) ).to eq( expected ) The second is that you''re comparing two new instances of Account, which will not be equal. puts Account.new == Account.new You probably just want to check what type of object was assigned to @account and that it is unpersisted. Something like (and my syntax might be off here): actual = assigns(:account) expect(actual).to be_a(Account) expect(actual).to be_new_record On Sunday, November 17, 2013 2:50:51 AM UTC-5, Peter wrote:> > > github.com/haloflightleader/bank/commit/88762271b5feda1390054b472cfb1de006c2b5da > > I corrected my code, but am still getting this: > > >> Failures: >> 1) AccountsController Get new assigned @account >> Failure/Error: expect( assigns(:account) ).to eq( [account] ) >> >> expected: [#<Account id: nil, name: nil, description: nil, >> account_number: nil, created_at: nil, updated_at: nil>] >> got: #<Account id: nil, name: nil, description: nil, >> account_number: nil, created_at: nil, updated_at: nil> >> >> (compared using ==) >> >> Diff: >> @@ -1,2 +1,2 @@ >> -[#<Account id: nil, name: nil, description: nil, account_number: >> nil, created_at: nil, updated_at: nil>] >> +#<Account id: nil, name: nil, description: nil, account_number: >> nil, created_at: nil, updated_at: nil> >> >> # ./spec/controllers/accounts_controller_spec.rb:21:in `block (3 >> levels) in <top (required)>'' >> Finished in 0.13115 seconds >> 18 examples, 1 failure >> Failed examples: >> rspec ./spec/controllers/accounts_controller_spec.rb:18 # >> AccountsController Get new assigned @account >> Randomized with seed 52138 > > > On Saturday, November 16, 2013 10:08:48 PM UTC-8, Peter wrote: >> >> Hello Everyone, >> >> Why is my controller test in the get method not working? >> >> github.com/haloflightleader/bank/blob/02695c7c5106b30e178d3a0d05125f8deedd5e67/spec/controllers/accounts_controller_spec.rb#L18 >> >> This is practically a copy from the rails guides and it works in my index >> test. The render test works... it''s only the assigns portion that refuses >> to work. >> >> I''m studying Rails, but am focusing on rspec because Rails by itself is >> easy and I feel that I don''t want to write anything without rspec being >> right next to it, even if I have to write the tests after. I have gone >> through several tutorials already: >> Michael Hartl''s, Pragmatic Studio, and Code School. >> >> So now, I just need to do it and gain proficiency. Thank you. >> >> p >> >> >>-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit groups.google.com/d/msgid/rubyonrails-talk/b42e63ad-c0c3-4bb8-a082-d027e8f6129a@googlegroups.com. For more options, visit groups.google.com/groups/opt_out.
Peter
2013-Nov-21 02:32 UTC
Re: why is my rspec controller test for get method not working?
Thanks for that. I didn''t know there was such a ''be_a()'' matcher. Where could I read more about the available permutations of ''be_''? Thank you. Also, I read again the Rails Guides on The Four Hashes of the Apocalypse. I thought assigns() would be a hash no matter what. I understand now that it was a hash in the index action because I gave it a hash. But the way it is being used in my new action, it''s not a hash, it''s just a new Account object that is empty. Thank you. On Sunday, November 17, 2013 6:59:14 AM UTC-8, Josh Jordan wrote:> > I would have to contest that you didn''t quite correct it then, eh? :p > > You wrote an expectation that says "I expect @account to be an array of > accounts that contains a single, specific instance of Account." Why are you > looking for an array? Your controller code looks right - it assigns > @account to be a new instance Account. > > So you, you have two problems here. The one I described you can illustrate > this way: > > expected = [account] > puts "Expected class: #{expected.class}" > puts "Actual class: #{assigns(:account).class}" > expect( assigns(:account) ).to eq( expected ) > > The second is that you''re comparing two new instances of Account, which > will not be equal. > > puts Account.new == Account.new > > You probably just want to check what type of object was assigned to > @account and that it is unpersisted. Something like (and my syntax might be > off here): > > actual = assigns(:account) > expect(actual).to be_a(Account) > expect(actual).to be_new_record > > On Sunday, November 17, 2013 2:50:51 AM UTC-5, Peter wrote: >> >> >> github.com/haloflightleader/bank/commit/88762271b5feda1390054b472cfb1de006c2b5da >> >> I corrected my code, but am still getting this: >> >> >>> Failures: >>> 1) AccountsController Get new assigned @account >>> Failure/Error: expect( assigns(:account) ).to eq( [account] ) >>> >>> expected: [#<Account id: nil, name: nil, description: nil, >>> account_number: nil, created_at: nil, updated_at: nil>] >>> got: #<Account id: nil, name: nil, description: nil, >>> account_number: nil, created_at: nil, updated_at: nil> >>> >>> (compared using ==) >>> >>> Diff: >>> @@ -1,2 +1,2 @@ >>> -[#<Account id: nil, name: nil, description: nil, >>> account_number: nil, created_at: nil, updated_at: nil>] >>> +#<Account id: nil, name: nil, description: nil, account_number: >>> nil, created_at: nil, updated_at: nil> >>> >>> # ./spec/controllers/accounts_controller_spec.rb:21:in `block (3 >>> levels) in <top (required)>'' >>> Finished in 0.13115 seconds >>> 18 examples, 1 failure >>> Failed examples: >>> rspec ./spec/controllers/accounts_controller_spec.rb:18 # >>> AccountsController Get new assigned @account >>> Randomized with seed 52138 >> >> >> On Saturday, November 16, 2013 10:08:48 PM UTC-8, Peter wrote: >>> >>> Hello Everyone, >>> >>> Why is my controller test in the get method not working? >>> >>> github.com/haloflightleader/bank/blob/02695c7c5106b30e178d3a0d05125f8deedd5e67/spec/controllers/accounts_controller_spec.rb#L18 >>> >>> This is practically a copy from the rails guides and it works in my >>> index test. The render test works... it''s only the assigns portion that >>> refuses to work. >>> >>> I''m studying Rails, but am focusing on rspec because Rails by itself is >>> easy and I feel that I don''t want to write anything without rspec being >>> right next to it, even if I have to write the tests after. I have gone >>> through several tutorials already: >>> Michael Hartl''s, Pragmatic Studio, and Code School. >>> >>> So now, I just need to do it and gain proficiency. Thank you. >>> >>> p >>> >>> >>>-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit groups.google.com/d/msgid/rubyonrails-talk/ae2a8d92-e589-40fc-90b9-c0c7c66140f9@googlegroups.com. For more options, visit groups.google.com/groups/opt_out.