У меня есть модуль, и он включает activemodel, и я хочу проверить его с помощью rspec.
Пока это мои настройки:
lib/
|__ my_module/
| |__ base.rb
|__ my_module.rb
spec/
|__ my_module_spec.rb
|__ spec_helper.rb
|__ support/
|__ shared_examples/
|__ active_model.rb
внутри my_class.rb:
require "active_model"
require "my_module/base"
внутри base.rb:
module MyModule
class Base
extend ActiveModel::Naming
include ActiveModel::Conversion
include ActiveModel::Validations
end
end
внутри my_module_spec.rb:
require 'spec_helper'
describe MyModule do
describe MyModule::Base do
it_behaves_like "ActiveModel"
end
end
внутри 'spec_helper.rb':
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
require 'my_module'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
RSpec.configure do |config|
end
внутри 'active_model.rb':
# taken from http://pivotallabs.com/users/jdean/blog/articles/1706-form-backing-objects-for-fun-and-profit
shared_examples_for "ActiveModel" do
require 'test/unit/assertions'
require 'active_model/lint'
include Test::Unit::Assertions
include ActiveModel::Lint::Tests
before do
@model = subject
end
ActiveModel::Lint::Tests.public_instance_methods.map { |method| method.to_s }.grep(/^test/).each do |method|
example(method.gsub('_', ' ')) { send method }
end
end
Я думал, что у меня все в порядке, но когда я попытался запустить bundle exec rspec spec
, я получаю следующие ошибки:
Failures:
1) MyModule MyModule::Base behaves like ActiveModel test to key
Failure/Error: example(method.gsub('_', ' ')) { send method }
2) MyModule MyModule::Base behaves like ActiveModel test to param
Failure/Error: example(method.gsub('_', ' ')) { send method }
3) MyModule MyModule::Base behaves like ActiveModel test to partial path
Failure/Error: example(method.gsub('_', ' ')) { send method }
4) MyModule MyModule::Base behaves like ActiveModel test valid?
Failure/Error: example(method.gsub('_', ' ')) { send method }
5) MyModule MyModule::Base behaves like ActiveModel test persisted?
Failure/Error: example(method.gsub('_', ' ')) { send method }
6) MyModule MyModule::Base behaves like ActiveModel test model naming
Failure/Error: example(method.gsub('_', ' ')) { send method }
7) MyModule MyModule::Base behaves like ActiveModel test errors aref
Failure/Error: example(method.gsub('_', ' ')) { send method }
8) MyModule MyModule::Base behaves like ActiveModel test errors full messages
Failure/Error: example(method.gsub('_', ' ')) { send method }
Что я здесь не так делаю? Как правильно проверить ActiveModel?
Заранее спасибо