0
我可以手動檢查並看到它的工作,但我想要一個rspec測試,將顯示我的create
方法添加一個cookie以及創建我的記錄。用我目前的代碼,沒有發現餅乾...任何想法?RSpec測試如果創建cookie
我的測試:
describe "POST create" do
subject { post :create, table: FactoryGirl.attributes_for(:table) }
it "creates table" do
expect { subject }.to change(Table, :count).by(1)
end
it "bakes cookies" do
expect(response.cookies["my_cookie"].to exist)
end
end
我的控制器:
def create
@table = Table.new(table_params)
if @table.save
bake_cookie @table.id
redirect_to show_table_path, notice: "Table created."
else
...
end
def bake_cookie table_id
cookies["my_cookie"] = { value: table_id, expires: 12.hours.from_now }
end
這是錯誤的'烤餅乾'它聲稱? –