Skip to content

Instantly share code, notes, and snippets.

@partydrone
Created September 27, 2012 16:38
Show Gist options
  • Save partydrone/3795013 to your computer and use it in GitHub Desktop.
Save partydrone/3795013 to your computer and use it in GitHub Desktop.
Cucumber tests fail for controller that doesn't inherit from ApplicationController
module Admin
class BaseController < ApplicationController
filter_access_to :index
def index
end
end
end
Matcher failed: has_selector?("h1", {:text=>"Patents"}) (MiniTest::Assertion)
(eval):6:in `must_have_selector'
./features/step_definitions/web_steps.rb:6:in `/^I should see "(.*?)"$/'
features/patents_administration.feature:5:in `Then I should see "Patents"'
Failing Scenarios:
cucumber -p guard features/patents_administration.feature:3 # Scenario: Patents index
<% title "Patents" %>
Feature: Patents Administration
Scenario: Patents index
Given I am on the admin patents page
Then I should see "Patents"
And the title should be "Wavetronix - Patents"
module Admin
class PatentsController < BaseController
before_filter :find_patent
def index
end
private
def find_patent
@patent = Patent.find(params[:id]) if params[:id]
end
end
end
Given /^I am on the (.*?) page$/ do |text|
visit eval("#{text.downcase.gsub(/\s/, '_')}_path(locale: 'en')")
end
Then /^I should see "(.*?)"$/ do |text|
page.must_have_selector('h1', text: text)
end
Then /^the title should be "(.*?)"$/ do |text|
page.must_have_selector('title', text: text)
end
@partydrone
Copy link
Author

Trying to implement this feature using BDD, the first step fails as expected: I need to implement Admin::PatentsController. Because it inherits from Admin::BaseController—which has its own index action and view—Admin::PatentsController inherits that action and view as well. When I override the BaseController implementation by explicitly defining an index action and view for the PatentsController, I can see the change in the browser—that it picks up the new index action and view, but the Cucumber step fails because it appears to still be looking at the BaseController index action and view.

Is there a better way to test this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment