Ruby on rails 为什么我使用json_规范的Cucumber场景失败了,最后定义的json在哪里?
Ruby on rails 为什么我使用json_规范的Cucumber场景失败了,最后定义的json在哪里?,ruby-on-rails,json,ruby,rspec,cucumber,Ruby On Rails,Json,Ruby,Rspec,Cucumber,这是一个非常新的问题:我正在使用Rails开发一个RESTAPI,我想用它来处理RSpec和Cucumber中的JSON。 我创建了我的功能测试(来自): 但我有一个错误: Given(/^I post to "(.*?)" with:$/) do |arg1, string| pending # express the regexp above with the code you wish you had end When(/^I get "(.*?)"$/) do |arg1| p
这是一个非常新的问题:我正在使用Rails开发一个RESTAPI,我想用它来处理RSpec和Cucumber中的JSON。 我创建了我的功能测试(来自): 但我有一个错误:
Given(/^I post to "(.*?)" with:$/) do |arg1, string|
pending # express the regexp above with the code you wish you had
end
When(/^I get "(.*?)"$/) do |arg1|
pending # express the regexp above with the code you wish you had
end
我认为方法get和post是由提供的,但我无法让系统识别它们
我还读到我需要定义一个last_json方法,但我不知道应该在哪里添加它
谢谢 如前所述,您需要编写“我发布”和“我获取”步骤
Cucumber步骤中可用的get
和post
方法由Capybara依赖的rack test提供,因此,我将使用机架测试方法编写这些步骤:
When /^I get "(.*?)"$/ do |path|
get path
end
Given /^I post to "(.*?)" with:$/ do |path, body|
post path, body
end
在env.rb或features/support中的另一个.rb文件中定义last_json
。如果使用机架测试,last\u json
也需要使用机架测试:
def last_json
last_response.body`enter code here`
end
def last_json
last_response.body`enter code here`
end