Вместо этого, которым я не горжусь, я в итоге сделал следующее:
Контроллер приложений
before_filter :authenticate_user!, :except => [:login]
# This action is supposed to only be accessed in the test environment.
# This is for being able of running the cucumber tests.
def login
@user = User.find(params[:id])
sign_in(@user)
current_user = @user
render :text => "user logged in"
end
Маршруты
# This is for being able of testing the application with cucumber. Since we are not using devise defaults login
match 'login/:id' => 'application#login', :as => 'login', :via => [:get] if Rails.env.test?
Действия пользователя
Given /^I am a logged in (student|employee)+ user$/ do |role|
@user = @that = Factory(:user, :role => role, :name => "#{role} User Name")
Given("that user is logged in")
end
Given /^that user is logged in$/ do
Given("I go to that users login page")
end
Путь
when /that users login page/
login_path(@that || @user)
Таким образом, в моих сценариях мне нужно только набрать:
Given I am a logged in student user
А остальное просто обычный огурец ...