samedi 24 octobre 2015

Testing with capybara and web mock rails application


Hello! I have a rails api and a front end on backbone. My api makes a call to an external api to get some resources.

I want to make an integration test of the full app in capybara. I am using web-mock.

An snipped of my spec_helper:

WebMock.disable_net_connect!(allow_localhost: true)

RSpec.configure do |config|
  config.before(:each) do
    stub_request(:get, "http://ift.tt/1k0JzS3").
      with(headers: {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
      to_return(status: 200, body: body, headers: {})
  end  
(...)
end

def body
  "{\"version\":\"9\",\"sports\":[{\"id\":101,\"title\":\"Football\"},{\"id\":100,\"title\":\"Tenis\"}]}"
end

My feature test:

feature 'sports displayment' do
  scenario 'user access to the site' do
    visit root_path

    expect(page).to have_text("Football")
  end
end

The error displayed is expected to find text "Football" in "" and if I embed a binding.pry on the controller it does not work (meaning that it is not going through it.

I am sure the app works, so it is a test problem.

A link to the app http://ift.tt/1LUeGcJ

Aucun commentaire:

Enregistrer un commentaire