Capybara DSL Receiver with MiniTest :: Spec?

A reading for Capybara (see Using Capybara with MiniTest :: Spec ) says that I can do this if I turn on the module correctly, but it does not give any illustrative examples of how ... I tried including the module as follows :

class MiniTest::Spec include Capybara::DSL end 

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

<main>': undefined method feature' for main: Object (NoMethodError)

How can I make it work the way it is written in the commented code?


specifications / reception / 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 

specifications / 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 
+6
source share
3 answers

This post has a good description of how you should do MinitTest :: Spec with capybara. There, it mainly includes Capybara :: DSL in the base class of all specifications, as in

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

this works well in our setup, but, of course, it does not renew MiniTest :: Spec.

+2
source

Here's a simple test setup of test_helper to run functional and integration tests in Rails using specification syntax. Based on the essence of tenderlove, the article mentioned above re: MiniTest with Capybara , as well as a lot of graceful and sources.

https://gist.github.com/1607879

0
source

You must add the minitest-rails-capybara gem to the Gemfile and add the word β€œfunction” to the end of the description as follows:

  feature 'RewardTerms feature',% 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

The special word "function" does not depend on the case, and may be a "browser". You can customize it by adding a line to test_helper.rb :

  MiniTest :: Spec.register_spec_type (/ FooBar \ z / i, Capybara :: Rails :: TestCase)
0
source

Source: https://habr.com/ru/post/901586/


All Articles