Rspec failure with :get. :get documentation?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Rspec failure with :get. :get documentation?

Ralph Shnelvar
Rspec failure with :get. :get documentation? I'm trying to simultaneously learn Rspec as well as implement a Rails app.  I am a complete Rspec novice.

I'm converting some code from Rails 4 to Rails 5.1.1 so that may be where the following problems lies.


Part of the Rspec messages I'm getting is:
 1) ArticlesController GET #new returns a success response
    Failure/Error: get :new, {}, valid_session
   
    ArgumentError:
      wrong number of arguments (given 2, expected 1)
    # ./spec/controllers/articles_controller_spec.rb:64:in `block (3 levels) in <top (required)>'

 2) User profile page user cannot see another user's profile
    Failure/Error: expect(page).to have_content 'Access denied.'
      expected to find text "Access denied." in "Home Menu Users Log out You are not authorized to perform this action. hello"
    # ./spec/features/user_show_spec.rb:18:in `block (2 levels) in <top (required)>'

. . .

The lines around  spec/controllers/articles_controller_spec.rb:62 are
 if true
 describe "GET #new" do
   it "returns a success response" do
     byebug
     get :new, {}, valid_session
     expect(response).to be_success
   end
 end
 end

As you can see, there is a byebug I put into articles_controller_spec.rb.  When I trace into (what I think is) the get, I end up with this:
[61, 70] in spec/controllers/articles_controller_spec.rb
  61:
  62:   if true
  63:   describe "GET #new" do
  64:     it "returns a success response" do
  65:       byebug
=> 66:       get :new, {}, valid_session
  67:       expect(response).to be_success
  68:     end
  69:   end
  70:   end
(byebug) s

[293, 302] in /home/real-estate-data-mining/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/memoized_helpers.rb
  293:           # Apply the memoization. The method has been defined in an ancestor
  294:           # module so we can use `super` here to get the value.
  295:           if block.arity == 1
  296:             define_method(name) { __memoized.fetch_or_store(name) { super(RSpec.current_example, &nil) } }
  297:           else
=> 298:             define_method(name) { __memoized.fetch_or_store(name) { super(&nil) } }
  299:           end
  300:         end
  301:
  302:         # Just like `let`, except the block is invoked by an implicit `before`
(byebug)


Questions:
1) Does the message "wrong number of arguments (given 2, expected 1)" refer to get?

2) Where can I find documentation on get?

3) Why does byebug's 's' end up on line 298 in method let?  (Yes, let, not get.) and not on the first executable statement in let?

4) Am I missing any relevant info in this posting?

5) And, finally, what is wrong with line 66 in articles_controller_spec.rb?














--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1303530647.20170709002635%40dos32.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rspec failure with :get. :get documentation?

Hassan Schroeder-2
On Sat, Jul 8, 2017 at 11:26 PM, Ralph Shnelvar <[hidden email]> wrote:

> I'm converting some code from Rails 4 to Rails 5.1.1 so that may be where
> the following problems lies.
>
>
> Part of the Rspec messages I'm getting is:
>  1) ArticlesController GET #new returns a success response
>     Failure/Error: get :new, {}, valid_session
>
>     ArgumentError:
>       wrong number of arguments (given 2, expected 1)

>  describe "GET #new" do
>    it "returns a success response" do
>      byebug
>      get :new, {}, valid_session

replace the line above with:

       get :new, params: {}, session: valid_session

>      expect(response).to be_success
>    end
>  end

I *believe* if you'd gone through converting to Rails 5.0 first you'd
have seen deprecation warnings about that. I think :-)

In any case, HTH.
--
Hassan Schroeder ------------------------ [hidden email]
twitter: @hassan
Consulting Availability : Silicon Valley or remote

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yAZZSp%2BY9uWbSnU3D_zBU7PHuTriRkq8Q7pM1JxW%3DUTAA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rspec failure with :get. :get documentation?

Ralph Shnelvar-2
Thank you so much, Hassan.

I didn't see any warnings.

Is there documentation I can look at that explains what "get" does?

Ralph


On Sunday, July 9, 2017 at 9:34:25 AM UTC-6, Hassan Schroeder wrote:
On Sat, Jul 8, 2017 at 11:26 PM, Ralph Shnelvar <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="297cIdTxCAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ral...@...> wrote:

> I'm converting some code from Rails 4 to Rails 5.1.1 so that may be where
> the following problems lies.
>
>
> Part of the Rspec messages I'm getting is:
>  1) ArticlesController GET #new returns a success response
>     Failure/Error: get :new, {}, valid_session
>
>     ArgumentError:
>       wrong number of arguments (given 2, expected 1)

>  describe "GET #new" do
>    it "returns a success response" do
>      byebug
>      get :new, {}, valid_session

replace the line above with:

       get :new, params: {}, session: valid_session

>      expect(response).to be_success
>    end
>  end

I *believe* if you'd gone through converting to Rails 5.0 first you'd
have seen deprecation warnings about that. I think :-)

In any case, HTH.
--
Hassan Schroeder ------------------------ <a href="javascript:" target="_blank" gdf-obfuscated-mailto="297cIdTxCAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">hassan.s...@...
twitter: @hassan
Consulting Availability : Silicon Valley or remote

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/286a5719-94ec-46f6-a0c1-720615fcdef3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rspec failure with :get. :get documentation?

Hassan Schroeder-2
On Sun, Jul 9, 2017 at 12:58 PM, Ralph Shnelvar
<[hidden email]> wrote:

> Is there documentation I can look at that explains what "get" does?

I'll assume not meaning "get" the HTTP verb, but rather how rspec
implements it for test purposes? Dunno about the latter, probably
need to dig into the source for that.

H*
--
Hassan Schroeder ------------------------ [hidden email]
twitter: @hassan
Consulting Availability : Silicon Valley or remote

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yBYBDGsoyrqbf8TALiAzii_cMR_D56NcDDnwJQz41%3DsgA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rspec failure with :get. :get documentation?

Frederick Cheung-2
In reply to this post by Ralph Shnelvar
On Sunday, July 9, 2017 at 9:55:30 AM UTC+1, Ralph Shnelvar wrote:



>
>
> Questions:
>
> 1) Does the message "wrong number of arguments (given 2, expected 1)" refer to get?
>
Yes
>

> 2) Where can I find documentation on get?
I would start here: http://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers
>
>
> 3) Why does byebug's 's' end up on line 298 in method let?  (Yes, let, not get.) and not on the first executable statement in let?

Ruby evaluates the arguments to get before calling get itself. In your case this is the valid_session,which was dynamically define by let, which is why you jump into let related code first. Were it not the the number of arguments error you would end up in get if you kept stepping

>
> 4) Am I missing any relevant info in this posting?
>
> 5) And, finally, what is wrong with line 66 in articles_controller_spec.rb?

Hassan's given you the answer there. Controller tests changed very substantially in rails 5 (rspec's controller specs are just a very thin layer on top of rails controller tests, so they've inherited these changes). There have been quite a few blog posts written about those changes (in addition to what is in the rails release notes), I am sure a quick Google will dig them up.

Fred

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/288d6655-ae86-4620-aa8f-edea081ca7ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...