2016-07-30 61 views

回答

1

我会写这样的事情

require "rails_helper" 

RSpec.describe 'Value integration', :type => :request do 

    it 'returns the correct number of items' do 
    get 'value.json' 

    expect(JSON.parse(response.body)).to have(2).items 
    end 
end 

注意,是一个request spec,controller spec可能是一个更好的选择,但是如果不知道一些关于你的控制器的内部信息,我将无法为你写出整个文件。

+0

我想知道,你为什么会免费为无礼的陌生人写代码? – mudasobwa

+0

@john:好像我错过了,告诉你请求规范属于'spec/requests'文件夹,而不是'spec/controllers'文件夹。或者您可能想要发布您的控制器,我们可以一起编写适当的控制器规格... – spickermann

+0

@mudasobwa:我喜欢编写简单代码片段的娱乐效果。 – spickermann