我在嘗試爲我幫助貢獻的應用編寫測試時遇到問題。我會承認,我的才能絕對在開發的前端,所以在進行rpsec測試時,我並不是最偉大的。如何在rspec中傳遞一個包含消息的對象?
我基本上是創建一個位置的測試,我有一個管理員能夠創建一個新的位置。我還爲這些地點創建了一家工廠。最終,我得到的問題是,當我嘗試1.我風了一個錯誤,說明
'change' requires either an object and message ('change(obj, :msg)') or a block ('change { }'). You passed an object but no message.
我真的不知道我能做些什麼來繞過這個,所以我想知道是否有人可以採取甘德和我做了什麼。
這裏是我廠:
FactoryGirl.define do
factory :location do |c|
c.name 'sample location'
c.phone '5555555555'
c.fax '5555555555'
location_id '123456'
association :address, factory: :address
end
這裏是我的規格。把那個在{}
括號改變對象 -
require 'spec_helper'
describe Admin::LocationController, type: :controller do
before(:all) do
@admin = create(:admin)
@location = create(:location)
end
after(:all) do
@admin.destroy
@location.destroy
end
let(:admin) {@admin}
let(:location) {@location}
before(:each) do
sign_in(:user, admin)
end
describe '#create' do
it 'creates a new location' do
expect{
post :create, location:{
name: 'sample location',
phone: '5555555555',
fax: '5555555555',
location_id: '123456',
address_attributes: {
address1: '12345 Some St',
city: 'Portland',
state: 'OR',
zip: '91237'
}
}
}.to change(Location.count).by(1)
new_location = Location.last
expect(new_location.name).to eq 'sample location'
expect(new_location.phone).to eq '5555555555'
expect(new_location.fax).to eq '5555555555'
expect(new_location.location_id). to eq '123456'
expect(new_location.address.address1).to eq '12345 Some St'
expect(new_location.address.city).to eq 'Portland'
expect(new_location.address.state).to eq 'OR'
expect(new_location.address.zip).to eq '91237'
end
end
end
的備選句法嘿謝謝芽!簡單的語法修改就是我需要的! – kdweber89