I'm using Cucumber with Capybara in Rails 4.2, but I'm not using RSpec. I've been sticking with Minitest. I've been using minitest:spec in most of my tests.
Whenever I try to use make an assertion with minitest or minitest:spec syntax in a Cucumber step I get an error saying the assertion method is undefined. For example this step:
Then (/^the state selector has no states$/) do
page.wont_have_selector(".my-css-class", :visible)
end
gives this error
undefined method `refute_selector' for nil:NilClass (NoMethodError)
(page.wont_have_selector is the minitest:spec syntax for the minitest method refute_selector)
I have a file features/support/minitest.rb with this content
require 'minitest'
require "minitest/rails/capybara"
require "minitest/spec"
module MiniTestAssertions
def self.extended(base)
base.extend(MiniTest::Assertions)
base.assertions = 0
end
attr_accessor :assertions
end
World(MiniTestAssertions)
Here is my test section of Gemfile
group :development, :test do
gem 'byebug'
gem 'web-console', '~> 2.0'
gem 'spring'
gem 'mocha', require: false
gem 'cucumber-rails', require: false
gem 'database_cleaner'
end
group :test do
gem 'minitest-reporters'
gem 'minitest-rails-capybara'
gem 'minitest-spec-rails'
gem 'capybara_minitest_spec'
gem 'launchy'
gem 'selenium-webdriver'
gem 'poltergeist'
end
the Gemfile.lock includes the following
capybara (2.4.4)
capybara_minitest_spec (1.0.5)
cucumber (1.3.20)
cucumber-rails (1.4.2)
minitest (5.7.0)
minitest-capybara (0.7.2)
minitest-metadata (0.5.3)
minitest-rails (2.2.0)
minitest-rails-capybara (2.1.1)
minitest-spec-rails (5.2.2)
rails (4.2.1)
Edit
It is only Capybara specific Minitest assertions that are not recognised in the Cucumber step file. If I change the step content to this:
assert true
refute false
then it passes. Also the Capybara Minitest assertions work fine in the test/features directory for doing integration testing outside Cucumber.
I think I have to add something to features/suport/minitest.rb so that the Capybara Minitest assertions get added to the Cucumber World, but I don't know what it is.
Edit
It's actually only the spec version of Capybara's minitest assertions that are giving the problem. If I change the content of the step to this:
refute_selector(".my-css-class", :visible)
then it works.
Edit
I think it's bug #10 in capybara_minitest_spec gem that I got reopened.