Where/how to include helper methods for capybara integration tests

前端 未结 3 1518
一生所求
一生所求 2021-02-01 16:58

I\"m using capybara for my integration/acceptance tests. They\'re in /spec/requests/ folder. Now I have a few helper methods that I use during acceptance tests. One

相关标签:
3条回答
  • 2021-02-01 17:35

    I used the given solution by @VasiliyErmolovich, but I changed the type to make it work:

    config.include YourHelper, :type => :feature
    
    0 讨论(0)
  • 2021-02-01 17:38

    Explicit way with ruby

    Using include:

    # spec/support/your_helper.rb
    class YourHelper
      def register_user(user)
        visit home_page
        fill_in 'user_name', :with => user.username
        fill_in 'password', :with => user.password
        click_button 'sign_up_button'
      end
    end
    
    describe MyRegistration do
      include YourHelper
    
      it 'registers an user' do
        expect(register_user(user)).to be_truthy
      end
    end
    
    0 讨论(0)
  • 2021-02-01 17:40

    Put your helper to the spec/support folder and do something like this:

    spec/support/:

    module YourHelper
      def register_user(user)
        visit home_page
        fill_in 'user_name', :with => user.username
        fill_in 'password', :with => user.password
        click_button 'sign_up_button'
      end
    end
    
    RSpec.configure do |config|
      config.include YourHelper, :type => :request
    end
    
    0 讨论(0)
提交回复
热议问题