Ruby on Rails Saturday, July 8, 2017

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?














No comments:

Post a Comment