用户创建/登录测试突然失败,但在生产中完美运行

时间:2011-11-04 21:28:38

标签: ruby-on-rails rspec

我的一些测试突然失败了,我不知道为什么。以下是我的测试失败:

Failures:

  1) Users signup success should make a new user
     Failure/Error: response.should render_template('users/show')
       Expected block to return true value.
     # ./spec/requests/users_spec.rb:33:in `block (5 levels) in <top (required)>'
     # ./spec/requests/users_spec.rb:26:in `block (4 levels) in <top (required)>'

  2) Users sign in/out success should sign a user in and out
     Failure/Error: controller.should be_signed_in
       expected signed_in? to return true, got false
     # ./spec/requests/users_spec.rb:67:in `block (4 levels) in <top (required)>'

以下是测试:

it "should make a new user" do
        lambda do
          visit signup_path
          fill_in "Name", :with => "Example User"
          fill_in "Email", :with => "user@example.com"
          fill_in "Password", :with => "foobar"
          fill_in "Confirmation", :with => "foobar"
          click_button
          response.should render_template('users/show')
        end.should change(User, :count).by(1)
      end

describe "success" do
      it "should sign a user in and out" do
        user = Factory(:user)
        visit signin_path
        fill_in "Email",    :with => user.email
        fill_in "Password", :with => user.password
        click_button
        controller.should be_signed_in
        click_link "Sign out"
        controller.should_not be_signed_in
      end
    end

事情是它之前通过,我唯一做的就是改变我的应用程序的主题(css)。我在生产中仔细检查过,它完美无缺。用户确实已签名/退出并且确实已创建。只有测试失败了。为什么会这样?

1 个答案:

答案 0 :(得分:0)

您对用户表有一些唯一性约束吗?由于您没有在那里使用工厂,您可能正在尝试创建已在数据库中的用户