Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 为什么我使用json_规范的Cucumber场景失败了,最后定义的json在哪里?_Ruby On Rails_Json_Ruby_Rspec_Cucumber - Fatal编程技术网

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
我认为方法getpost是由提供的,但我无法让系统识别它们

我还读到我需要定义一个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