- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试使用 Minitest,发现了一些我似乎无法找到解释的行为
我有一个非常简单的模型测试文件如下:
require 'minitest_helper'
describe User do
before do
@user = User.new(name: "Example User", email: "user@example.com",
password: "foobards", password_confirmation: "foobards")
end
describe "with admin attribute set to 'true'" do
before { @user.toggle!(:admin) }
it { @user.admin.must_equal true }
end
end
当我在“rake db:test:prepare”之后第一次运行这段代码时,测试通过了
当我连续第二次运行它时,它给我一个错误:
test_0001_anonymous 0:00:00.132
ERROR SQLite3::ConstraintException: column email is not unique: INSERT INTO "users" ("admin", "created_at", "email", "name", "password_digest", "updated_at") VALUES (?, ?, ?, ?, ?, ?)
然而,如果我取出
,这个错误似乎不会发生before { @user.toggle!(:admin) }
我的minitest_helper.rb如下:
ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
require "minitest/autorun"
require "capybara/rails"
require "active_support/testing/setup_and_teardown"
class IntegrationTest < MiniTest::Spec
include Rails.application.routes.url_helpers
include Capybara::DSL
register_spec_type(/integration$/, self)
end
class HelperTest < MiniTest::Spec
include ActiveSupport::Testing::SetupAndTeardown
include ActionView::TestCase::Behavior
register_spec_type(/Helper$/, self)
end
Turn.config.format = :outline
我似乎无法理解这是一个错误还是(更有可能)我遗漏了什么。请比我更了解的人解释一下吗?
最佳答案
toggle!
方法保存记录。因此,当您第二次运行测试时,数据库中已经存在一条电子邮件为“user@example.com”的记录。并且保证电子邮件地址唯一性的验证失败。
尝试使用toggle
(没有爆炸声)。
关于ruby-on-rails - Minitest 在连续两次运行中给出不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10864845/
我正在阅读 minitest 的模拟功能。 require "minitest/autorun" mock = MiniTest::Mock.new mock.expect(:use_any_stri
当我运行我的规范时,我得到这个错误,即使我从来没有在我的代码中的任何地方包含 minitest: Warning: you should require 'minitest/autorun' inst
我一直在使用 MiniTest 学习 TDD/BDD。我想弄清楚的是我的代码的哪些部分应该使用 MiniTest::Unit::TestCase 进行测试,哪些部分应该使用 MiniTest::Spe
请帮忙: 我想用 minitest 来使用 shoulda。 这是我得到的异常: NoMethodError: undefined method `run_teardown_hooks' for #:
请帮忙: 我想用 minitest 来使用 shoulda。 这是我得到的异常: NoMethodError: undefined method `run_teardown_hooks' for #:
我正在尝试启动并运行我的模型测试,但我的终端出现错误 rake aborted! uninitialized class variable @@current in MiniTest::Unit::T
考虑将 Minitest 用于现有的 Rails 3.2。 我试图了解 minitest-rails 和 minitest-spec-rails 之间的区别。 最佳答案 minitest-spec-r
我一直在使用 Ruby 2.1 附带的 MiniTest,没有任何问题。我将子类化 MiniTest::Unit:TestCase 创建几个方法,如“test_simple”,一切正常。我会毫无问题地
我正在使用 minitest 的规范语法和描述 block 。在我的 minitest_helper.rb (每个规范文件需要)中,我有: Minitest::Test.i_suck_and_my_t
我正在使用 minitest 的规范语法和描述 block 。在我的 minitest_helper.rb (每个规范文件需要)中,我有: Minitest::Test.i_suck_and_my_t
在 Ruby 1.9.1 中,我发现 ctrl + c 只会杀死一个单元测试,而你无法停止整个测试程序的运行方式。 相比之下,在 Ruby 1.8 中的 test/unit 下,它会停止所有测试。 1
我有一个方法“退出”: def quit puts "Good bye!" exit end 我想做的是做一个小型测试断言 quit 方法确实退出了,但我尝试过的都不起作用。寻找输入。提前致谢
我正在尝试在我的代码中测试该方法,但第二个测试返回错误 undefined local variable or method 'params' 测试方法的正确方法是什么?还是我需要对 main.rb
Ruby 1.9 有很棒的 Unicode 支持,是吗? # encoding: utf-8 require 'minitest/spec' require 'minitest/autorun' de
我使用 minitest 为我的网络项目编写测试。 我有一个模拟对象,模拟了 3 个方法。该对象表示具有多个属性的数据库实体(hanami 模型)。现在,如果我多次为一个属性调用“getter”,我会
我在我的迷你测试中使用自定义断言,我想对我的断言进行单元测试。当然,我可以测试快乐路径,但我想断言测试实际上失败了。 module Minitest module Assertions d
我正在查看我的测试用例结果,很难看出我的测试中的一个小故障是从哪里来的。 我正在处理合理大小的数据结构 - 我不想更改 to_s 方法,以便它对 minitest diff 稍微好一些。 我看过记者,
是否有用于 minitest 的替代测试报告器,它会在测试运行时显示哪些测试已损坏以及错误消息是什么,而不必等到结束。 最佳答案 你可以看看 minitest-reporters gem 。它允许您以
(已在 https://www.ruby-forum.com/topic/6876320 发布,但在这里交叉发布,因为到目前为止我还没有收到回复)。 关于在 Minitest 和/或 Test::Un
每当我尝试 assert_equal 两个对象时,我总是会遇到这样的错误: No visible difference in the User#inspect output. You sh
我是一名优秀的程序员,十分优秀!