How to test API with rspec and capybara on rails?

I created a controller that can read api data at a special url.

def category @data = get_api_data(param1) end def get_api_data(param1) "http://my_api_url/param1=#{param1}" end 

After creating the view, I see the result from the browser.

If I use rspec + capybara to run a function test

 visit category_path('param1') 

Then I want to confirm that the api data will be shown in the field of view

 expect(page).to have_field('name', with: 'aaa') 

But the @data value @data always null. What for? Do i need to make api url access message from test code? If necessary, how to do it? The visit method cannot accept other parameters.

+6
source share
1 answer

Capybara is not intended to test an API. You have to go with Rspec and Airbone: https://github.com/brooklynDev/airborne

+3
source

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


All Articles