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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.