Difficulties to run tests
Madabinghy opened this issue · 1 comments
Hi,
I have some difficulties to run the tests as expected in the doc.
I have a controller test : domains_controller_test.rb
`
require 'test_helper'
module Api
module V1
class DomainsControllerTest < ActionController::TestCase
setup do
#@routes = Engine.routes
#@user = users(:one)
end
def create_token(sub: nil)
_payload = payload.merge({sub: sub})
JWT.encode _payload, OpenSSL::PKey::RSA.new(FirebaseIdToken::Testing::Certificates.private_key), 'RS256'
end
def payload
# payload.json
end
test 'should success get api v1 users ' do
get :show, headers: create_token(@user.id)
assert_response :success
end
end
end
end`
When I run the test, I have this error
test_should_success_get_api_v1_users_#Api::V1::DomainsControllerTest (0.03s)
NameError: NameError: uninitialized constant Api::V1::DomainsControllerTest::Engine
test/controllers/domains_controller_test.rb:7:in `block in class:DomainsControllerTest
I don't know if it's an error from my rails tests configuration. After some researches on rails Engines and on this type of error on stackoverflow, I didn't found how to figure it out.
It may come from my misunderstanding of some basic Rails stuffs.
Maybe the FirebaseIdToken.test! should init an Engine ?
When I comment the setup of the test case and hard code
get :show, headers: create_token(1)
I get an
ArgumentError: wrong number of arguments (given 1, expected 0)
So I tried
get :show, headers: create_token() NoMethodError: undefined method 'merge' for nil:NilClass
So I am looking for where the payload variable is initialized. I'am stuck there, so I try to have some help to understand what I'am doing wrong.
Thank you for your help.
Emeric