【发布时间】:2014-06-19 15:07:19
【问题描述】:
我在名为 images_controller.rb 的 rails 控制器中有一个索引操作,它从外部服务获取图像。我正在尝试编写黄瓜场景,并且正在努力解决如何编写/删除我的访问索引页面步骤。如果不发出请求,我怎么能将它获取的图像存根?
特点:
Scenario: Image Index
Given an image exists on the image server
When I am on the images page
Then I should see images
到目前为止的步骤:
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
控制器:
class ImagesController < ApplicationController
def index
response = image_server_connection.get(IMAGE_SERVER['base_url'] + "/all_images")
@images = JSON.parse(response.body)
end
end
【问题讨论】:
标签: ruby-on-rails ruby cucumber capybara