【发布时间】:2014-06-24 12:39:23
【问题描述】:
这是一个非常新手的问题:我正在使用 Rails 开发一个 REST API,我想使用json_spec 来处理 RSpec 和 Cucumber 中的 JSON。
我创建了我的功能测试(来自here):
Feature: User API
Scenario: User list
Given I post to "/users.json" with:
"""
{
"first_name": "Steve",
"last_name": "Richert"
}
"""
And I keep the JSON response at "id" as "USER_ID"
When I get "/users.json"
Then the JSON response should have 1 user
And the JSON response at "0" should be:
"""
{
"id": %{USER_ID},
"first_name": "Steve",
"last_name": "Richert"
}
"""
但是我收到了这个错误:
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方法是capybara提供的,但我无法让系统识别它们。
我还读到我需要定义一个 last_json 方法,但我不知道应该在哪里添加它。
谢谢!
【问题讨论】:
标签: ruby-on-rails json ruby rspec cucumber