Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capybara Acceptance DSL with MiniTest::Spec?

The readme for Capybara (see Using Capybara with MiniTest::Spec) says that I can do this if I include the module correctly, but it doesn't give any illustrative examples of how... I've tried including the module like this:

class MiniTest::Spec
  include Capybara::DSL
end

... to no avail. I keep getting this error:

<main>': undefined methodfeature' for main:Object (NoMethodError)

How can I get it to work as it's written in the commented-out code?


spec/acceptance/api/reward_terms_spec.rb:

require "#{Dir.pwd}/spec/acceptance/acceptance_helper"

# this syntax works...

describe 'reward terms acceptance test' do
  include Capybara::DSL

  describe '#index' do
    specify {
      visit '/reward_terms'
      # ...
    }
  end
end

# this syntax doesn't work...

# feature 'RewardTerms', %q{
#   In order to get all reward terms available to me
#   As an API client
#   I want to list all active RewardTerms
# } do

#   background do
#     set_api_headers
#   end

#   scenario 'RewardTerm index' do
#     visit '/reward_terms'
#     ...
#   end
# end

spec/acceptance/acceptance_helper.rb:

ENV["RAILS_ENV"] = "test"
require "#{Dir.pwd}/config/environment"

require 'minitest/autorun'
require 'capybara/rails'

def set_api_headers(device_id = 'abcd1234')
  header 'Accept', 'application/json'
  header 'X-Device-Id', device_id
end
like image 325
neezer Avatar asked Nov 16 '11 04:11

neezer


1 Answers

There is a nice description in this post for how you should make MinitTest::Spec run with capybara. There he basically includes the Capybara::DSL into the base class of all the specs as in

class RequestSpec < MiniTest::Spec
  include Rails.application.routes.url_helpers
  include Capybara::DSL
end

this works rather nicely in our setup, but of course it does not reopen the MiniTest::Spec.

like image 138
Patru Avatar answered Nov 04 '22 08:11

Patru