黄瓜功能重定向失败

时间:2018-12-04 20:48:27

标签: ruby-on-rails cucumber

即时通讯(im)新增了Rails,黄瓜和BDD 我正在尝试使用方案测试我的注册过程

这是我的注册功能

    Feature: Signup
      As a guest
      I want to create an account
      so that i can use all site's services

      Scenario: User successfully register
        Given I am a guest
        And I am on the homepage
        When I register a valid account
        Then I should be on profile page
        #And I should see a welcome message

这是步骤文件

Given (/^I am a guest$/) do
  @user = nil
end

And (/^I am on the homepage$/) do
  visit root_path
end

When (/^I register a valid account$/) do
  register(FactoryBot.create(:user))
end

Then (/^I should be on profile page$/) do
  puts current_path
end



module LoginSteps
  def register(user)
    visit registrazione_path
    fill_in('user_username', with: user.username)
    fill_in('user_email', with: user.email)
    fill_in('user_password', with: user.password)
    fill_in('user_password_confirmation', with: user.password)
    fill_in('user_comune', with: user.comune)
    fill_in('flatpickr-input', with: user.data_nascita)
    click_button("Crea account")
  end
end


World(LoginSteps)

我在第4步输入了“ puts”,以检查注册后iam进入哪个页面 问题是当它应该在/ users / id

上时,它重定向到/ users

应用程序运行正常,但测试失败 有什么建议吗? 谢谢

1 个答案:

答案 0 :(得分:0)

您需要对其进行调试以查看发生了什么。我将执行以下操作。

1)暂时将javascript标记添加到您的方案中,以便它将在浏览器中运行,然后您可以查看会发生什么。 (这是可选的,但我发现它对于调试方案非常有用)

2)在单击按钮之前进行调试,以便查看是否正确填写了要注册的字段

3)在注册控制器中进行调试,以便可以检查params哈希值。

此外,您可能想调试FactoryBot.create(:user)的工作。我认为可能没有创建密码,因为User模型中的password字段几乎可以肯定是加盐的哈希值,而不是纯文本密码。

相关问题