【问题标题】:How do I test a FactoryGirl generated user with Sorcery?如何使用 Sorcery 测试 FactoryGirl 生成的用户?
【发布时间】:2013-07-26 00:43:48
【问题描述】:

我尝试了各种不同的东西,但我无法让以下工作。

这是我的工厂:

FactoryGirl.define do
  factory :user do
    username              "user"
    email                 "user@email.com"
    password              "userpass"
    password_confirmation "userpass"
  end
end

这是我的测试:

描述“使用有效信息”做 let(:user) { FactoryGirl.create(:user) }

  before do
    fill_in 'Username',   with: user.username.upcase
    fill_in 'Password',   with: user.password
    click_button 'Sign in'
    binding.pry
  end

编辑:binding.pry 告诉我user.passwordnil。对密码进行硬编码似乎有效,尽管它不是那么好。

【问题讨论】:

    标签: ruby-on-rails testing rspec factory-bot sorcery


    【解决方案1】:

    这可行,但需要在密码中进行硬编码:

    这是我的工厂:

    FactoryGirl.define do
      factory :user do
        username              "user"
        email                 "user@email.com"
        password              "userpass"
        password_confirmation "userpass"
      end
    end
    

    这是我的测试:

    描述“有有效信息”做 let(:user) { FactoryGirl.create(:user) }

      before do
        fill_in 'Username',   with: user.username
        fill_in 'Password',   with: "userpass"
        click_button 'Sign in'
      end
    

    【讨论】:

      猜你喜欢
      • 2015-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多