samedi 26 janvier 2019

How can I prove a simple method of a controller on Rails?

I would like to try the custom_pow method of ApplicationController controller in order to verify what works correctly, but whenever I execute rspec, the following message appears:

wrong number of arguments (given 1, expected 2)

In ApplicationController:

def custom_pow
    params[:x] * params[:x]
end

In ApplicationController (_spec):

Rspec.describe ApplicationController, type: :controller do
    test "should get custom_pow" do
        get custom_pow, params: {x:1}
        assert_response :success
    end
 end

I would like to corroborate that custom_pow works correctly. I would specially like to indicate an expectative, for example, of 64 and to try the method with a value of 8.

Thank you.

Aucun commentaire:

Enregistrer un commentaire