【问题标题】:How to to check correct Title is present in JSON by connecting如何通过连接检查 JSON 中是否存在正确的标题
【发布时间】:2016-07-29 11:29:15
【问题描述】:

我是Rspec 的新手。如何编写控制器代码以连接到Rspec 中的localhost:3000/v.json 链接并检查标题是否符合预期?

JSON format is  {id: 1, title: "new"}

请帮忙!

【问题讨论】:

标签: ruby-on-rails rspec


【解决方案1】:

您需要对您的控制器进行功能测试,该测试会影响您的操作,如下所示:

@expected = { 
  id: 1,
  title: "new"
}.to_json

# replace with action name / params as necessary, perhaps also passing "id: 1"?
get :v, format: "json"
response.body.should == @expected

【讨论】:

  • json 对象将出现在我需要连接到 URL 然后验证的链接中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-06-10
  • 2017-03-24
  • 2015-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-10
相关资源
最近更新 更多