Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Login 用cucumber测试设备登录_Login_Devise_Cucumber - Fatal编程技术网

Login 用cucumber测试设备登录

Login 用cucumber测试设备登录,login,devise,cucumber,Login,Devise,Cucumber,我知道理想的做法是填写登录表单并遵循流程。问题是我没有使用Desive登录。在使用Facebook和fb_graph gem进行身份验证后,我会登录到我的应用程序中 因此,Desive sign_视图中只有“与Facebook连接”链接,但我能够看到该路径,我假设如果有帖子发到该url,该用户将尝试登录该url 我试着直接用cucumber向sign_in(该视图为空)发送帖子,即使响应正常,用户也没有登录 Given /^I am a logged in user$/ do @user =

我知道理想的做法是填写登录表单并遵循流程。问题是我没有使用Desive登录。在使用Facebook和fb_graph gem进行身份验证后,我会登录到我的应用程序中

因此,Desive sign_视图中只有“与Facebook连接”链接,但我能够看到该路径,我假设如果有帖子发到该url,该用户将尝试登录该url

我试着直接用cucumber向sign_in(该视图为空)发送帖子,即使响应正常,用户也没有登录

Given /^I am a logged in user$/ do
  @user = Factory(:user)
  res = post("/users/sign_in", :email => @user.email, :password => "password")
  p res
end
我如何测试这个

谢谢

更新:

场景如下所示:

Scenario: Going to the index page
  Given I am a logged in user
  And there is a subject created
  And there is 1 person for that subject
  When I go to that subject persons index page
  And show me the page
  Then I should see "Back to Subjects list"

我不得不说,这是我想出的一些讨厌的猴子补丁

将此添加到我的应用程序\u控制器

if Rails.env.test?
  prepend_before_filter :stub_current_user
  # UGLY MONKEY PATCH. we need a current user here.
  def stub_current_user
    unless user_signed_in?
      @user = Factory(:user)
      sign_in(@user)
      current_user = @user
    end
  end
end

请记住,我的申请表中没有签名,我正在使用Desive。也许以后,我会尝试寻找一种更好的方法,但现在,这让我可以把事情做好。

而不是那样做,我不自豪的是,我最终做了以下几件事:

应用程序控制器

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
路径

这样,在我的场景中,我只需键入:

Given I am a logged in student user
剩下的只是普通黄瓜

Given I am a logged in student user