- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Rails 4.2.4、Rspec 3.3.1、shouda-matchers 3.0.0。
我正进入(状态
#...
358) Participant validations
Failure/Error: it { should ensure_length_of(:coresp_country).is_at_most(255) }
NoMethodError:
undefined method `ensure_length_of' for #<RSpec::ExampleGroups::Participant::Validations:0x0000000f40aec0>
# ./spec/models/participant_spec.rb:100:in `block (3 levels) in <top (required)>'
359) Participant validations company
Failure/Error: it { should ensure_length_of(:company).is_at_most(255) }
NoMethodError:
undefined method `ensure_length_of' for #<RSpec::ExampleGroups::Participant::Validations::Company:0x0000000f414ab0>
# ./spec/models/participant_spec.rb:149:in `block (4 levels) in <top (required)>'
360) Participant validations company declared_type = COMPANY
Failure/Error: it { should validate_presence_of(:company) }
NoMethodError:
undefined method `validate_presence_of' for #<RSpec::ExampleGroups::Participant::Validations::Company::DeclaredTypeCOMPANY:0x0000000f429c58>
#...
还有更多类似的失败(看起来 shoulda-matchers 不起作用)。
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'spec_helper'
require 'rspec/rails'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
Rails.logger.level = 4
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
config.include FactoryGirl::Syntax::Methods
config.include Sorcery::TestHelpers::Rails
config.include Macros::Controller::Security
end
FactoryGirl.reload
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
spec_helper.rb:
require 'simplecov_helper'
require 'webmock/rspec'
WebMock.disable_net_connect!(allow_localhost: true)
require 'rspec/collection_matchers'
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.filter_run :focus
config.run_all_when_everything_filtered = true
config.disable_monkey_patching!
config.expose_dsl_globally = true
config.default_formatter = 'doc' if config.files_to_run.one?
config.order = :random
Kernel.srand config.seed
end
spec/compositions/api
中失败文件夹,我在其中使用 gem。
最佳答案
shoulda-matchers 3.0 有选择地使其匹配器可用。我使用的 ActiveModel 匹配器仅混合到模型规范中 ( af98a23 )。
我有两个选择来解决这个问题:
spec/models
文件夹; type: :model
到 spec/compositions/api
中每个类的顶级描述块文件夹。 ensure_inclusion_in
,
ensure_length_of
)开头的匹配器重命名为
validate_inclusion_in
,
validate_length_of
(
55c8d09 )。
关于ruby-on-rails - rails/rspec 看不到 shoulda 匹配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33280731/
我遇到了一个问题,我的模型上的自定义验证导致所有 shoulda 验证失败。 本质上: class User birthday errors.add(:birthday, "Some s
请帮忙: 我想用 minitest 来使用 shoulda。 这是我得到的异常: NoMethodError: undefined method `run_teardown_hooks' for #:
请帮忙: 我想用 minitest 来使用 shoulda。 这是我得到的异常: NoMethodError: undefined method `run_teardown_hooks' for #:
我有一个 User 模型,它有一个 items 的子关联。项目的 :name 对用户来说应该是唯一的,但它应该允许不同的用户拥有同名的项目。 Item 模型当前设置为: class Item < Ap
在 Rails Test Prescriptions 一书中(b10.0,第 176 页),有如下所示的单行断言示例: 应该“成功”{ assert_response :success } 这对我来说
我是单元测试领域的新手;我现在只使用单元测试大约 2 个月。当我在 Ruby 中进行单元测试时,我目前遵循 TDD 风格并使用 Test::Unit::TestCase。我还阅读了 RSpec 以及它
我正在使用一些Shoulda rspec匹配器来测试我的模型,其中之一是: describe Issue do it { should_not allow_value("test").for(:p
我正在尝试使用 rspec 和 shoulda 匹配器作为我的新测试框架,但我对如何获得 should validate_uniqueness_of(:attribute) 感到有些困惑。测试通过。这
我使用带有 shoulda-matcher 的 rspec-rails 来测试我的模型。这是代码: user_ticket.rb class UserTicket < ActiveRecord::Ba
使用 shoulda-matchers 的正确格式是什么?和 RSpec 的新 expect syntax ? 最佳答案 虽然人们当然可以将 shoulda-matchers 与新的期望语法一起使用,
这是我的: context "Create ingredient from string" do context "1 cups butter" do setup
用较小的代码示例再次问这个问题: # this is a dummy shoulda macro that creates a context def self.macro_context
我对模型的属性进行了以下验证: validates :on_ride_photo, presence: true, inclusion: { in: [true, false] } 然后我有以
我在类(class)中遇到以下属性问题。我也有一个在数据库级别强制执行的日期属性,存在为真: 验证 :date, presence: true 除此之外,我需要为以下两个属性强制组合唯一性 valid
我正在尝试让整个设置在我的 Mac 上与 Autotest/Growl/Shoulda 一起工作,以测试我正在为 Authlogic 开发的 gem。 .我过去经常使用 RSpec,但想切换到 Sho
我的 avatar_parts_spec.rb 中有一个 shoulda 匹配器,但我无法让它通过: 测试: require 'rails_helper' RSpec.describe AvatarP
我有一个模型,该模型在数据库级别具有唯一索引,并且模型验证检查范围为多列的唯一性。 # db level add_index :table1, %i[fk_belongs_to_id col1 col
在我的 device 模型中,我有 enum device_type: { ios: 1 , android: 2 } validates :device_type, presence: true,
我有一个自定义验证器(位于 app/validators/uri_validator.rb)用于: validates :link, uri: true 如何在我的规范中指定它? 理想情况下,我希望进
我有以下 Rspec 测试: describe Productlimit do before(:each) do @productlimit = Factory.create(:produ
我是一名优秀的程序员,十分优秀!