Reputation: 2616
It's a simple (and maybe common) question but I can't find a clear answer.
I'm testing my rails engine from the dummy application with Rspec and Capybara. In my feature spec I need to use a ApplicationController
method named get_component()
with a specific argument. How can I do it?
My feature test is:
require "rails_helper"
describe "My test", type: :feature do
it "gets a component if slug is provided" do
# ...
component = ApplicationController.get_component( slug )
# ...
end
end
Which returns
NoMethodError:
undefined method `get_component' for #<ApplicationController:0x007ff7207234f8>
I don't want to mock/stub that method, I want it to run for real.
Also, the application ApplicationController
should inherit the engine one, shouldn't it? So it's right to call ApplicationController, isn't it?
Upvotes: 0
Views: 794
Reputation: 36880
Remember that get_component
is an instance method, not a class method, so you can only call it on an ApplicationController object, not on the class itself. Try this instead...
component = ApplicationController.new.get_component( slug )
Upvotes: 2