未定义的方法`permit' for" 1":String - RSPEC

时间:2016-06-21 16:36:00

标签: ruby-on-rails ruby rspec

我有点荒谬但我真的不知道这个错误试图告诉我什么?我是rspec的新手,对我来说这是一个新手。为了清楚起见,我会发布我的代码 - 错误:未定义的方法`permit' for" 1":String |

控制器:

def subscriber_params
  params.require(:subscriber).permit(:first_name, :last_name, :email, :phone_number)
end

SPEC:       要求" rails_helper"

describe SubscribersController do
  include Devise::TestHelpers

  let(:user) { FactoryGirl.create(:user) }
  let(:subscriber) { FactoryGirl.create(:subscriber) }

  it "creates a new comment" do
    sign_in(user)
    comment = FactoryGirl.attributes_for(:comment)

    expect { post :create, subscriber: subscriber, comment: comment }.to change(Comment, :count).by(1)
  end
end

错误:

enter image description here

1 个答案:

答案 0 :(得分:5)

更改

let(:subscriber) { FactoryGirl.create(:subscriber) }

let(:subscriber) { FactoryGirl.attributes_for(:subscriber) }

因为您要将订阅者的属性添加到请求而不是订阅者的实例