使测试对手指和眼睛来说变得轻松
Shoulda 可以帮助您编写更易于理解、可维护的 Rails 专用测试 在 Minitest 和 Test::Unit 中。
[查看最近版本的变更。][变更记录]
作为一个 umbrella gem, shoulda gem 本身不包含任何代码,但它提供了一个接口,
而是从另外两个宝石中引入了行为:
require "test_helper"
class UserTest < ActiveSupport::TestCase
context "associations" do
should have_many(:posts)
end
context "validations" do
should validate_presence_of(:email)
should allow_value("[email protected]").for(:email)
should_not allow_value("not-an-email").for(:email)
end
context "#name" do
should "consist of first and last name" do
user = User.new(first_name: "John", last_name: "Smith")
assert_equal "John Smith", user.name
end
end
end这里的 context 和 should 方法来自 Shoulda Context; 相匹配器 (例如 have_many, allow_value) 来自 Shoulda Matchers。
暂无开放 Issues,或尚未同步最近议题。