您可以检查响应对象并验证它是否包含期望值:
@expected = { :flashcard => @flashcard, :lesson => @lesson, :success => true}.to_jsonget :action # replace with action name / params as necessaryresponse.body.should == @expected
编辑
将此更改为a
post会比较麻烦。这是一种处理方法:
it "responds with JSON" do my_model = stub_model(MyModel,:save=>true) MyModel.stub(:new).with({'these' => 'params'}) { my_model } post :create, :my_model => {'these' => 'params'}, :format => :json response.body.should == my_model.to_json end
请注意,它
mock_model不会响应
to_json,因此需要一个
stub_model或真实的模型实例。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)