I have created a controller that can read api data by a special url.
def category
@data = get_api_data(param1)
end
def get_api_data(param1)
"http://my_api_url/param1=#{param1}"
end
After I create a view, I can see the result from browser.
If I use rspec + capybara to do the feature test
visit category_path('param1')
Then I want to confirm a api data will be shown in view
expect(page).to have_field('name', with: 'aaa')
But the @data
value always be null. Why? Is it necessary to do a api url access post from test code? If it is necessary, how to do? The visit
method can't take other params.
Capybara is not designed for testing APIs. You should go with Rspec and Airbone: https://github.com/brooklynDev/airborne
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With