I have an index action in a rails controller called images_controller.rb that fetches images from an external service. I am trying to write cucumber scenarios and am struggling with how to write/stub out my visit index page step. How could I stub out the images it fetches without it making the request?
Feature:
Scenario: Image Index
Given an image exists on the image server
When I am on the images page
Then I should see images
Steps so far:
Given(/^an image exists on the image server$/) do
image_server_url = IMAGE_SERVER['base_url'] + "/all_images"
image = "image.png"
image_path = "development_can/image.png"
response = [{image_path => [image]}].to_json
stub_request(:get, image_server_url).to_return(JSON.parse(response))
end
When(/^I am on the images page$/) do
body = "[{\"image/development_app\":[\"the_pistol.jpeg\"]},{\"image/development_can\":[\"kaepernick.jpg\"]}]"
@images = JSON.parse(body)
end
Then(/^I should see images$/) do
end
controller:
class ImagesController < ApplicationController
def index
response = image_server_connection.get(IMAGE_SERVER['base_url'] + "/all_images")
@images = JSON.parse(response.body)
end
end