Rspec - GET在特定的json视图上显示respond_to

时间:2013-07-25 06:25:34

标签: json ruby-on-rails-3 rspec rspec-rails

我正在尝试在我的应用程序上使用Rspec-rails,但是当我尝试验证请求的响应时,我失败了。

这是我的代码:

# app/controllers/user_controller.rb

# GET api/users/:id
def show
  @user = User.find(:id)
  respond_to do |format|
    format.json {render template: "/api/users/detailed"}
  end
end

...

# spec/controllers/api/users_controller_spec.rb

require "spec_helper"

describe Api::UsersController do
  include Devise::TestHelpers

  describe "GET #show" do
    user = FactoryGirl.build(:user)
    it "assigns the requested user to @user" do
      get :show, :format => 'json', :id => user.id
      assigns(:user).should eq(@user)
    end

    it "renders the #detailed  view" do
      get :show, :format => 'json', :id => user.id
      response.should be_respond_to("api/users/detailed")
      #expect(response).to render_template("api/users/detailed")

      #expect(subject).to render_template("/api/users/detailed")
      #render(:template => "/api/users/detailed.json.rabl", :format => "json")
      #response.should render_template("/api/users/detailed.json.rabl")
    end
  end

我评论了我测试过的部分内容 我只想确保我的控制器respond_to是一个名为"api/users/detailed"的模板。

大多数情况下,我有以下错误:

expecting <"api/users/detailed"> but rendering with <"">

我很确定我的请求称为控制器,因为第一个描述"assigns the requested user to @user"有效。

0 个答案:

没有答案