Desi Tsvet.
Desi Tsvet.

Reputation: 21

Capybara visit always gives me error 404

I am doing some modular Sinatra app and making tests with rspec and Capybara. The problem is that I always get 'Not found' error 404 when trying to visit a page. When I use the command 'bundle exec rackup' and go to the same url but in the browser everything is ok. Here's my spec:

    require "spec_helper"
    require_relative '../../routes/user_routes'

    set :environment, :test


    RSpec.describe RubyPlay, type: :feature do
      include Rack::Test::Methods

      def app
        RubyPlay # this defines the active application for this test
      end

      before { visit '/' }
      it "should allow accessing the home page" do
        p page.html # prints Not found
        p page.status_code # 404
        expect(page).to have_content 'Ruby Play'
      end
    end

bundle exec rspec:

   RubyPlay should allow accessing the home page
   Failure/Error: expect(page).to have_content 'Ruby Play'
   expected to find text "Ruby Play" in "Not Found"

I've never done tests in Sinatra and have no idea what might be wrong... :)

Upvotes: 0

Views: 780

Answers (1)

Desi Tsvet.
Desi Tsvet.

Reputation: 21

I found a solution - I just had to add:

    Capybara.app = RubyPlay

to the spec_helper.rb file! Now it can find its routes...

Upvotes: 1

Related Questions