Load test DB to be sure it is up-to-date.
(for example you want to run specs on CS then you need to load RS DB as CS uses rs models from RS)
$ bundle exec rake db:test:load
Run all existing specs, in CS, for instance
$ rspec
or run Guard to work with single spec (then save the spec file)
$ guard
CS and RE are used rs_models from RS.
So, CS and RE take rs factories from RS the same way: locally I added to CS & RE config a path to rs factories:
factories_path '/Users/d/projects/livepepper/resource_server/spec/factories'
Currently there is no such path in config/application/config_test
nor in CS master or in RE.
group :test do
gem 'database_cleaner' # https://github.com/DatabaseCleaner/database_cleaner
gem 'factory_bot_rails' # https://github.com/thoughtbot/factory_bot_rails
gem 'guard', require: false
gem 'guard-bundler', require: false
gem 'guard-rspec', require: false # https://github.com/guard/guard-rspec
gem 'rspec'
gem 'rspec-rails' # https://github.com/rspec/rspec-rails#rspec-rails---
gem 'shoulda-matchers' # https://github.com/thoughtbot/shoulda-matchers
gem 'vcr' # https://github.com/vcr/vcr#vcr
gem 'webmock'
end
$ bundle install
$ rails generate rspec:install
create .rspec
create spec
create spec/spec_helper.rb
create spec/rails_helper.rb
Settings in RS
.rspec
https://github.com/livepepper-dev/resource_server/blob/master/.rspec
spec/rails_helper.rb
https://github.com/livepepper-dev/resource_server/blob/master/spec/rails_helper.rb#L1
spec/spec_helper.rb
https://github.com/livepepper-dev/resource_server/blob/master/spec/spec_helper.rb
For CS, RE there are the same settings.
$ bundle exec guard init
create Guardfile
Guardfile in RS https://github.com/livepepper-dev/resource_server/blob/master/Guardfile
For CS, RE there are the same settings.
In spec/rails_helper.rb
RS https://github.com/livepepper-dev/resource_server/blob/master/spec/rails_helper.rb
require 'factory_bot_rails'
Dir[Rails.root.join("spec/rs_factories/**/*.rb")].each { |f| require f } # path to factories
...
RSpec.configure do |config|
...
config.include FactoryBot::Syntax::Methods
...
end
For CS, RE there are the same settings.
Currently some factories for rs_models are used in CS, RE, RS specs and they are stored in RS resource_server/spec/factories
https://github.com/livepepper-dev/resource_server/tree/master/spec/factories
Most of them are with rs_
prefix for consistency with rs_models. But some old of them are still not renamed to not break specs.
Provides specs with helper methods
For example, for testing AR models validation, relations with:
ActiveModel matchers https://github.com/thoughtbot/shoulda-matchers#activemodel-matchers
ActiveRecord matchers https://github.com/thoughtbot/shoulda-matchers#activerecord-matchers
or to test controllers:
ActionController matchers https://github.com/thoughtbot/shoulda-matchers#actioncontroller-matchers
Provides strategies for cleaning test database by adding settings below to spec/rails_helper.rb
config.before(:suite) do
DatabaseCleaner.strategy = :transaction # to run each case in DB transaction
DatabaseCleaner.clean_with(:truncation)
end
RS https://github.com/livepepper-dev/resource_server/blob/master/spec/rails_helper.rb#L38
For CS, RE there are the same settings.
Installed and used only for RS.
In spec/rails_helper.rb
https://github.com/livepepper-dev/resource_server/blob/master/spec/rails_helper.rb#L22
VCR.configure do |config|
config.cassette_library_dir = "spec/vcr_cassettes"
config.hook_into :webmock
config.configure_rspec_metadata!
config.default_cassette_options = { record: :new_episodes, :match_requests_on => [:method, :uri, :body] }
end
new_episodes
replay previously recorded interactions. Record new interactions for similar requests when some request data changed (will write a new request below the previous in cassette).
match_requests_on
how VCR matches requests.
Cassettes directory in RS https://github.com/livepepper-dev/resource_server/tree/master/spec/vcr_cassettes
Example of spec with VCR in RS https://github.com/livepepper-dev/resource_server/blob/master/spec/models/sms/siminn_gateway_spec.rb#L1
Success case cassette https://github.com/livepepper-dev/resource_server/blob/master/spec/vcr_cassettes/Sms_SiminnGateway/run/Success/1_1_1_1.yml
Fail case cassette https://github.com/livepepper-dev/resource_server/blob/master/spec/vcr_cassettes/Sms_SiminnGateway/run/Fail/1_1_2_1.yml