Tôi đang cố gắng để có được giá trị cookie trong bước Dưa chuột:Capybara & Cucumber | Bắt cookie
Bước định nghĩa
When /^I log in$/ do
# code to log in
end
Then /^cookies should be set$/ do
cookies[:author].should_not be_nil
end
khiển
class SessionsController < ApplicationController
def create
cookies[:author] = 'me'
redirect_to authors_path
end
end
Nhưng nó không hoạt động:
Kết quả
expected: not nil
got: nil
Thú vị, rằng trong các ví dụ RSpec mọi công việc tốt:
khiển Spec
require 'spec_helper'
describe SessionsController do
describe 'create' do
it 'sets cookies' do
post :create
cookies[:author].should_not be_nil
end
end
end
Làm thế nào tôi có thể nhận được giá trị cookie trong các bước dưa chuột sử dụng Capybara?
Cảm ơn.
Debian GNU/Linux 6.0.4;
Ruby 1.9.3;
Ruby on Rails 3.2.1;
Dưa chuột 1.1.4;
dưa chuột-Rails 1.2.1;
Capybara 1.1.2;
Rack-Test 0.6.1.
Bạn có thể trích xuất dưới dạng phương thức tùy chỉnh như được giải thích ví dụ: https://github.com/cucumber/cucumber/wiki/Cucumber-Backgrounder#steps-within-steps--an-anti-pattern (về phía cuối của phần). – juanrpozo