Ich habe Probleme beim Versuch, einen Test für eine App zu schreiben, zu der ich einen Beitrag leisten kann. Ich werde im Vorfeld zugeben, dass meine Talente definitiv am vorderen Ende der Entwicklung stehen, und wenn es um das Testen von rpsec geht, bin ich nicht der Größte.Wie übergibt man ein Objekt mit einer Nachricht in rspec?
Ich bin im Grunde erstellen einen Test für einen Standort, und ich habe einen Administrator kann einen neuen Speicherort erstellen. Ich habe auch eine Fabrik für diese Orte geschaffen. Letztlich ist das Problem, das ich erhalte, wenn ich versuche ich mit einem Fehler, der besagt weiß ich wirklich
'change' requires either an object and message ('change(obj, :msg)') or a block ('change { }'). You passed an object but no message.
Hier ist meine Fabrik:
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
Hier ist mein spec.
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
Hey danke Knospe !! Diese einfache Syntaxänderung war alles was ich brauchte! – kdweber89