mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +02:00
Merge branch 'rspec' into registry-475
This commit is contained in:
commit
864631dba7
15 changed files with 60 additions and 404 deletions
|
@ -1,10 +0,0 @@
|
||||||
inherit_from: .rubocop.yml
|
|
||||||
|
|
||||||
#
|
|
||||||
# Turn off during guard runs
|
|
||||||
#
|
|
||||||
|
|
||||||
# turn off comment intention check during development
|
|
||||||
# because NerdCommenter honors commented code intentions
|
|
||||||
Style/CommentIndentation:
|
|
||||||
Enabled: false
|
|
6
Gemfile
6
Gemfile
|
@ -114,12 +114,8 @@ gem 'jquery-ui-rails', '5.0.5'
|
||||||
|
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
gem 'guard', '2.12.9' # run tests automatically
|
|
||||||
gem 'spring', '1.3.6'
|
gem 'spring', '1.3.6'
|
||||||
gem 'spring-commands-rspec', '1.0.4'
|
gem 'spring-commands-rspec', '1.0.4'
|
||||||
gem 'guard-rails', '0.7.1' # run EPP server automatically
|
|
||||||
gem 'guard-rspec', '4.5.2'
|
|
||||||
gem 'guard-rubocop', '1.2.0'
|
|
||||||
gem 'rubocop', '0.48.1'
|
gem 'rubocop', '0.48.1'
|
||||||
|
|
||||||
# deploy
|
# deploy
|
||||||
|
@ -129,7 +125,7 @@ end
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
gem 'capybara'
|
gem 'capybara'
|
||||||
gem 'rspec-rails', '~> 3.5'
|
gem 'rspec-rails', '~> 3.6'
|
||||||
gem 'fabrication', '2.13.2' # Replacement for fixtures
|
gem 'fabrication', '2.13.2' # Replacement for fixtures
|
||||||
gem 'phantomjs-binaries'
|
gem 'phantomjs-binaries'
|
||||||
gem 'phantomjs'
|
gem 'phantomjs'
|
||||||
|
|
83
Gemfile.lock
83
Gemfile.lock
|
@ -165,7 +165,7 @@ GEM
|
||||||
daemons-rails (1.2.1)
|
daemons-rails (1.2.1)
|
||||||
daemons
|
daemons
|
||||||
multi_json (~> 1.0)
|
multi_json (~> 1.0)
|
||||||
database_cleaner (1.5.3)
|
database_cleaner (1.6.1)
|
||||||
deep_cloneable (2.1.1)
|
deep_cloneable (2.1.1)
|
||||||
activerecord (>= 3.1.0, < 5.0.0)
|
activerecord (>= 3.1.0, < 5.0.0)
|
||||||
descendants_tracker (0.0.4)
|
descendants_tracker (0.0.4)
|
||||||
|
@ -193,7 +193,6 @@ GEM
|
||||||
ffi (1.9.18)
|
ffi (1.9.18)
|
||||||
figaro (1.1.1)
|
figaro (1.1.1)
|
||||||
thor (~> 0.14)
|
thor (~> 0.14)
|
||||||
formatador (0.2.5)
|
|
||||||
globalid (0.3.7)
|
globalid (0.3.7)
|
||||||
activesupport (>= 4.1.0)
|
activesupport (>= 4.1.0)
|
||||||
grape (0.12.0)
|
grape (0.12.0)
|
||||||
|
@ -206,26 +205,6 @@ GEM
|
||||||
rack-accept
|
rack-accept
|
||||||
rack-mount
|
rack-mount
|
||||||
virtus (>= 1.0.0)
|
virtus (>= 1.0.0)
|
||||||
guard (2.12.9)
|
|
||||||
formatador (>= 0.2.4)
|
|
||||||
listen (>= 2.7, <= 4.0)
|
|
||||||
lumberjack (~> 1.0)
|
|
||||||
nenv (~> 0.1)
|
|
||||||
notiffany (~> 0.0)
|
|
||||||
pry (>= 0.9.12)
|
|
||||||
shellany (~> 0.0)
|
|
||||||
thor (>= 0.18.1)
|
|
||||||
guard-compat (1.2.1)
|
|
||||||
guard-rails (0.7.1)
|
|
||||||
guard (~> 2.11)
|
|
||||||
guard-compat (~> 1.0)
|
|
||||||
guard-rspec (4.5.2)
|
|
||||||
guard (~> 2.1)
|
|
||||||
guard-compat (~> 1.1)
|
|
||||||
rspec (>= 2.99.0, < 4.0)
|
|
||||||
guard-rubocop (1.2.0)
|
|
||||||
guard (~> 2.0)
|
|
||||||
rubocop (~> 0.20)
|
|
||||||
gyoku (1.3.1)
|
gyoku (1.3.1)
|
||||||
builder (>= 2.1.2)
|
builder (>= 2.1.2)
|
||||||
haml (4.0.7)
|
haml (4.0.7)
|
||||||
|
@ -236,7 +215,7 @@ GEM
|
||||||
haml (>= 4.0.6, < 5.0)
|
haml (>= 4.0.6, < 5.0)
|
||||||
html2haml (>= 1.0.1)
|
html2haml (>= 1.0.1)
|
||||||
railties (>= 4.0.1)
|
railties (>= 4.0.1)
|
||||||
hashdiff (0.3.2)
|
hashdiff (0.3.4)
|
||||||
hashie (3.5.5)
|
hashie (3.5.5)
|
||||||
hashie-forbidden_attributes (0.1.1)
|
hashie-forbidden_attributes (0.1.1)
|
||||||
hashie (>= 3.0)
|
hashie (>= 3.0)
|
||||||
|
@ -279,13 +258,8 @@ GEM
|
||||||
libv8 (3.16.14.19)
|
libv8 (3.16.14.19)
|
||||||
libxml-ruby (3.0.0)
|
libxml-ruby (3.0.0)
|
||||||
liquid (3.0.6)
|
liquid (3.0.6)
|
||||||
listen (3.1.5)
|
|
||||||
rb-fsevent (~> 0.9, >= 0.9.4)
|
|
||||||
rb-inotify (~> 0.9, >= 0.9.7)
|
|
||||||
ruby_dep (~> 1.2)
|
|
||||||
loofah (2.0.3)
|
loofah (2.0.3)
|
||||||
nokogiri (>= 1.5.9)
|
nokogiri (>= 1.5.9)
|
||||||
lumberjack (1.0.11)
|
|
||||||
mail (2.6.5)
|
mail (2.6.5)
|
||||||
mime-types (>= 1.16, < 4)
|
mime-types (>= 1.16, < 4)
|
||||||
method_source (0.8.2)
|
method_source (0.8.2)
|
||||||
|
@ -296,7 +270,7 @@ GEM
|
||||||
open4 (~> 1.3.4)
|
open4 (~> 1.3.4)
|
||||||
rake
|
rake
|
||||||
mini_portile2 (2.1.0)
|
mini_portile2 (2.1.0)
|
||||||
minitest (5.10.1)
|
minitest (5.10.2)
|
||||||
monetize (1.6.0)
|
monetize (1.6.0)
|
||||||
money (~> 6.8)
|
money (~> 6.8)
|
||||||
money (6.8.3)
|
money (6.8.3)
|
||||||
|
@ -309,14 +283,10 @@ GEM
|
||||||
railties (>= 3.0)
|
railties (>= 3.0)
|
||||||
multi_json (1.12.1)
|
multi_json (1.12.1)
|
||||||
multi_xml (0.6.0)
|
multi_xml (0.6.0)
|
||||||
nenv (0.3.0)
|
|
||||||
netrc (0.11.0)
|
netrc (0.11.0)
|
||||||
nokogiri (1.7.1)
|
nokogiri (1.7.1)
|
||||||
mini_portile2 (~> 2.1.0)
|
mini_portile2 (~> 2.1.0)
|
||||||
nori (2.6.0)
|
nori (2.6.0)
|
||||||
notiffany (0.1.1)
|
|
||||||
nenv (~> 0.1)
|
|
||||||
shellany (~> 0.0)
|
|
||||||
nprogress-rails (0.1.6.7)
|
nprogress-rails (0.1.6.7)
|
||||||
open4 (1.3.4)
|
open4 (1.3.4)
|
||||||
orm_adapter (0.5.0)
|
orm_adapter (0.5.0)
|
||||||
|
@ -345,7 +315,7 @@ GEM
|
||||||
erubis
|
erubis
|
||||||
que (~> 0.8)
|
que (~> 0.8)
|
||||||
sinatra
|
sinatra
|
||||||
rack (1.6.5)
|
rack (1.6.8)
|
||||||
rack-accept (0.4.5)
|
rack-accept (0.4.5)
|
||||||
rack (>= 0.4)
|
rack (>= 0.4)
|
||||||
rack-mount (0.8.3)
|
rack-mount (0.8.3)
|
||||||
|
@ -389,9 +359,6 @@ GEM
|
||||||
activesupport (>= 3.0)
|
activesupport (>= 3.0)
|
||||||
i18n
|
i18n
|
||||||
polyamorous (~> 1.1)
|
polyamorous (~> 1.1)
|
||||||
rb-fsevent (0.9.8)
|
|
||||||
rb-inotify (0.9.8)
|
|
||||||
ffi (>= 0.5.0)
|
|
||||||
rdoc (4.3.0)
|
rdoc (4.3.0)
|
||||||
ref (2.0.0)
|
ref (2.0.0)
|
||||||
request_store (1.1.0)
|
request_store (1.1.0)
|
||||||
|
@ -401,27 +368,27 @@ GEM
|
||||||
http-cookie (>= 1.0.2, < 2.0)
|
http-cookie (>= 1.0.2, < 2.0)
|
||||||
mime-types (>= 1.16, < 4.0)
|
mime-types (>= 1.16, < 4.0)
|
||||||
netrc (~> 0.8)
|
netrc (~> 0.8)
|
||||||
rspec (3.5.0)
|
rspec (3.6.0)
|
||||||
rspec-core (~> 3.5.0)
|
rspec-core (~> 3.6.0)
|
||||||
rspec-expectations (~> 3.5.0)
|
rspec-expectations (~> 3.6.0)
|
||||||
rspec-mocks (~> 3.5.0)
|
rspec-mocks (~> 3.6.0)
|
||||||
rspec-core (3.5.4)
|
rspec-core (3.6.0)
|
||||||
rspec-support (~> 3.5.0)
|
rspec-support (~> 3.6.0)
|
||||||
rspec-expectations (3.5.0)
|
rspec-expectations (3.6.0)
|
||||||
diff-lcs (>= 1.2.0, < 2.0)
|
diff-lcs (>= 1.2.0, < 2.0)
|
||||||
rspec-support (~> 3.5.0)
|
rspec-support (~> 3.6.0)
|
||||||
rspec-mocks (3.5.0)
|
rspec-mocks (3.6.0)
|
||||||
diff-lcs (>= 1.2.0, < 2.0)
|
diff-lcs (>= 1.2.0, < 2.0)
|
||||||
rspec-support (~> 3.5.0)
|
rspec-support (~> 3.6.0)
|
||||||
rspec-rails (3.5.2)
|
rspec-rails (3.6.0)
|
||||||
actionpack (>= 3.0)
|
actionpack (>= 3.0)
|
||||||
activesupport (>= 3.0)
|
activesupport (>= 3.0)
|
||||||
railties (>= 3.0)
|
railties (>= 3.0)
|
||||||
rspec-core (~> 3.5.0)
|
rspec-core (~> 3.6.0)
|
||||||
rspec-expectations (~> 3.5.0)
|
rspec-expectations (~> 3.6.0)
|
||||||
rspec-mocks (~> 3.5.0)
|
rspec-mocks (~> 3.6.0)
|
||||||
rspec-support (~> 3.5.0)
|
rspec-support (~> 3.6.0)
|
||||||
rspec-support (3.5.0)
|
rspec-support (3.6.0)
|
||||||
rubocop (0.48.1)
|
rubocop (0.48.1)
|
||||||
parser (>= 2.3.3.1, < 3.0)
|
parser (>= 2.3.3.1, < 3.0)
|
||||||
powerpack (~> 0.1)
|
powerpack (~> 0.1)
|
||||||
|
@ -429,7 +396,6 @@ GEM
|
||||||
ruby-progressbar (~> 1.7)
|
ruby-progressbar (~> 1.7)
|
||||||
unicode-display_width (~> 1.0, >= 1.0.1)
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
||||||
ruby-progressbar (1.8.1)
|
ruby-progressbar (1.8.1)
|
||||||
ruby_dep (1.5.0)
|
|
||||||
ruby_parser (3.8.4)
|
ruby_parser (3.8.4)
|
||||||
sexp_processor (~> 4.1)
|
sexp_processor (~> 4.1)
|
||||||
safe_yaml (1.0.4)
|
safe_yaml (1.0.4)
|
||||||
|
@ -455,7 +421,6 @@ GEM
|
||||||
thor (~> 0.14)
|
thor (~> 0.14)
|
||||||
selectize-rails (0.12.1)
|
selectize-rails (0.12.1)
|
||||||
sexp_processor (4.8.0)
|
sexp_processor (4.8.0)
|
||||||
shellany (0.0.1)
|
|
||||||
simplecov (0.10.0)
|
simplecov (0.10.0)
|
||||||
docile (~> 1.1.0)
|
docile (~> 1.1.0)
|
||||||
json (~> 1.8)
|
json (~> 1.8)
|
||||||
|
@ -513,7 +478,7 @@ GEM
|
||||||
wasabi (3.5.0)
|
wasabi (3.5.0)
|
||||||
httpi (~> 2.0)
|
httpi (~> 2.0)
|
||||||
nokogiri (>= 1.4.2)
|
nokogiri (>= 1.4.2)
|
||||||
webmock (2.3.2)
|
webmock (3.0.1)
|
||||||
addressable (>= 2.3.6)
|
addressable (>= 2.3.6)
|
||||||
crack (>= 0.3.2)
|
crack (>= 0.3.2)
|
||||||
hashdiff
|
hashdiff
|
||||||
|
@ -556,10 +521,6 @@ DEPENDENCIES
|
||||||
factory_girl_rails
|
factory_girl_rails
|
||||||
figaro (= 1.1.1)
|
figaro (= 1.1.1)
|
||||||
grape (= 0.12.0)
|
grape (= 0.12.0)
|
||||||
guard (= 2.12.9)
|
|
||||||
guard-rails (= 0.7.1)
|
|
||||||
guard-rspec (= 4.5.2)
|
|
||||||
guard-rubocop (= 1.2.0)
|
|
||||||
haml-rails (= 0.9.0)
|
haml-rails (= 0.9.0)
|
||||||
hashie-forbidden_attributes (= 0.1.1)
|
hashie-forbidden_attributes (= 0.1.1)
|
||||||
html2haml (= 2.1.0)
|
html2haml (= 2.1.0)
|
||||||
|
@ -593,7 +554,7 @@ DEPENDENCIES
|
||||||
rails-settings-cached (= 0.4.1)
|
rails-settings-cached (= 0.4.1)
|
||||||
ransack (= 1.5.1)
|
ransack (= 1.5.1)
|
||||||
rest-client
|
rest-client
|
||||||
rspec-rails (~> 3.5)
|
rspec-rails (~> 3.6)
|
||||||
rubocop (= 0.48.1)
|
rubocop (= 0.48.1)
|
||||||
sass-rails (= 5.0.6)
|
sass-rails (= 5.0.6)
|
||||||
sdoc (= 0.4.1)
|
sdoc (= 0.4.1)
|
||||||
|
|
52
Guardfile
52
Guardfile
|
@ -1,52 +0,0 @@
|
||||||
group :red_green_refactor, halt_on_fail: true do
|
|
||||||
# start test EPP server automatically on port 8989,
|
|
||||||
# be sure you have apache2 configured to
|
|
||||||
# accept EPP request on port 701, what proxy to 8989.
|
|
||||||
# port and environment is just for correct notification, all is overwritten by CLI
|
|
||||||
# guard :rails, port: 8989, environment: 'test' do
|
|
||||||
# # guard :rails, port: 8989, environment: 'test', CLI: 'RAILS_ENV=test unicorn -p 8989' do
|
|
||||||
# watch('Gemfile.lock')
|
|
||||||
# watch(%r{^(config|lib)/.*})
|
|
||||||
# end
|
|
||||||
|
|
||||||
# guard :rspec, cmd: 'spring rspec --fail-fast', notification: false do
|
|
||||||
guard :rspec, cmd: 'spring rspec', notification: false do
|
|
||||||
watch(%r{^spec/.+_spec\.rb$})
|
|
||||||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
|
||||||
watch('spec/spec_helper.rb') { "spec" }
|
|
||||||
|
|
||||||
# Rails example
|
|
||||||
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
|
||||||
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
|
||||||
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
|
||||||
watch(%r{^app/controllers/epp/(.+)_(controller)\.rb$}) { |m| ["spec/epp/#{m[1].sub(/s$/,'')}_spec.rb"] }
|
|
||||||
watch(%r{^app/models/epp/(.+)\.rb$}) { |m| "spec/epp/#{m[1]}_spec.rb" }
|
|
||||||
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
|
||||||
watch('config/routes.rb') { "spec/routing" }
|
|
||||||
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
|
||||||
watch('spec/rails_helper.rb') { "spec" }
|
|
||||||
|
|
||||||
# epp tests
|
|
||||||
watch('app/helpers/epp/contacts_helper.rb') { 'spec/epp/contact_spec.rb' }
|
|
||||||
watch('app/helpers/epp/domains_helper.rb') { 'spec/epp/domain_spec.rb' }
|
|
||||||
# Capybara features specs
|
|
||||||
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
|
||||||
|
|
||||||
# Turnip features and steps
|
|
||||||
watch(%r{^spec/acceptance/(.+)\.feature$})
|
|
||||||
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
|
||||||
end
|
|
||||||
|
|
||||||
# Martin does not want rubocop
|
|
||||||
unless Socket.gethostname == 'martin'
|
|
||||||
guard :rubocop,
|
|
||||||
all_on_start: false,
|
|
||||||
cli: '--display-cop-names -c .rubocop-guard.yml -f fuubar',
|
|
||||||
notification: false do
|
|
||||||
|
|
||||||
watch(%r{.+\.rb$})
|
|
||||||
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
|
||||||
watch(%r{(?:.+/)?\.rubocop-guard\.yml$}) { |m| File.dirname(m[0]) }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,7 +1,7 @@
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :admin_user do
|
factory :admin_user do
|
||||||
username 'test'
|
username 'test'
|
||||||
email 'test@test.com'
|
sequence(:email) { |n| "test#{n}@test.com" }
|
||||||
password 'a' * AdminUser.min_password_length
|
password 'a' * AdminUser.min_password_length
|
||||||
password_confirmation { password }
|
password_confirmation { password }
|
||||||
country_code 'de'
|
country_code 'de'
|
||||||
|
|
|
@ -9,7 +9,6 @@ require 'support/requests/session_helpers'
|
||||||
require 'support/requests/epp_helpers'
|
require 'support/requests/epp_helpers'
|
||||||
require 'support/features/session_helpers'
|
require 'support/features/session_helpers'
|
||||||
require 'support/matchers/alias_attribute'
|
require 'support/matchers/alias_attribute'
|
||||||
require 'support/matchers/active_job'
|
|
||||||
require 'support/matchers/epp/code'
|
require 'support/matchers/epp/code'
|
||||||
|
|
||||||
require 'support/capybara'
|
require 'support/capybara'
|
||||||
|
@ -28,6 +27,7 @@ RSpec.configure do |config|
|
||||||
config.include Features::SessionHelpers, type: :feature
|
config.include Features::SessionHelpers, type: :feature
|
||||||
config.include AbstractController::Translation, type: :request
|
config.include AbstractController::Translation, type: :request
|
||||||
config.include AbstractController::Translation, type: :feature
|
config.include AbstractController::Translation, type: :feature
|
||||||
|
config.include AbstractController::Translation, type: :mailer
|
||||||
config.include Requests::EPPHelpers, type: :request
|
config.include Requests::EPPHelpers, type: :request
|
||||||
|
|
||||||
config.define_derived_metadata(file_path: %r[/spec/features/]) do |metadata|
|
config.define_derived_metadata(file_path: %r[/spec/features/]) do |metadata|
|
||||||
|
|
|
@ -6,17 +6,7 @@ if ENV['TRAVIS']
|
||||||
SimpleCov.start
|
SimpleCov.start
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
# https://github.com/rspec/rspec-rails/issues/1076
|
|
||||||
config.around :each, type: :view do |example|
|
|
||||||
config.mock_with :rspec do |mocks|
|
|
||||||
mocks.verify_partial_doubles = false
|
|
||||||
example.run
|
|
||||||
mocks.verify_partial_doubles = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# rspec-expectations config goes here. You can use an alternate
|
# rspec-expectations config goes here. You can use an alternate
|
||||||
# assertion/expectation library such as wrong or the stdlib/minitest
|
# assertion/expectation library such as wrong or the stdlib/minitest
|
||||||
# assertions if you prefer.
|
# assertions if you prefer.
|
||||||
|
|
|
@ -1,252 +0,0 @@
|
||||||
require "active_job/base"
|
|
||||||
require "active_job/arguments"
|
|
||||||
|
|
||||||
# This matcher is needed because it is absent it rspec-rails 3.3.2
|
|
||||||
|
|
||||||
module RSpec
|
|
||||||
module Rails
|
|
||||||
module Matchers
|
|
||||||
# Namespace for various implementations of ActiveJob features
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
module ActiveJob
|
|
||||||
# rubocop: disable Style/ClassLength
|
|
||||||
# @private
|
|
||||||
class Base < RSpec::Matchers::BuiltIn::BaseMatcher
|
|
||||||
def initialize
|
|
||||||
@args = []
|
|
||||||
@queue = nil
|
|
||||||
@at = nil
|
|
||||||
@block = Proc.new {}
|
|
||||||
set_expected_number(:exactly, 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
def with(*args, &block)
|
|
||||||
@args = args
|
|
||||||
@block = block if block.present?
|
|
||||||
self
|
|
||||||
end
|
|
||||||
|
|
||||||
def on_queue(queue)
|
|
||||||
@queue = queue
|
|
||||||
self
|
|
||||||
end
|
|
||||||
|
|
||||||
def at(date)
|
|
||||||
@at = date
|
|
||||||
self
|
|
||||||
end
|
|
||||||
|
|
||||||
def exactly(count)
|
|
||||||
set_expected_number(:exactly, count)
|
|
||||||
self
|
|
||||||
end
|
|
||||||
|
|
||||||
def at_least(count)
|
|
||||||
set_expected_number(:at_least, count)
|
|
||||||
self
|
|
||||||
end
|
|
||||||
|
|
||||||
def at_most(count)
|
|
||||||
set_expected_number(:at_most, count)
|
|
||||||
self
|
|
||||||
end
|
|
||||||
|
|
||||||
def times
|
|
||||||
self
|
|
||||||
end
|
|
||||||
|
|
||||||
def once
|
|
||||||
exactly(:once)
|
|
||||||
end
|
|
||||||
|
|
||||||
def twice
|
|
||||||
exactly(:twice)
|
|
||||||
end
|
|
||||||
|
|
||||||
def thrice
|
|
||||||
exactly(:thrice)
|
|
||||||
end
|
|
||||||
|
|
||||||
def failure_message
|
|
||||||
"expected to enqueue #{base_message}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def failure_message_when_negated
|
|
||||||
"expected not to enqueue #{base_message}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def message_expectation_modifier
|
|
||||||
case @expectation_type
|
|
||||||
when :exactly then "exactly"
|
|
||||||
when :at_most then "at most"
|
|
||||||
when :at_least then "at least"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def supports_block_expectations?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def check(jobs)
|
|
||||||
@matching_jobs_count = jobs.count do |job|
|
|
||||||
if serialized_attributes.all? { |key, value| value == job[key] }
|
|
||||||
args = ::ActiveJob::Arguments.deserialize(job[:args])
|
|
||||||
@block.call(*args)
|
|
||||||
true
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
case @expectation_type
|
|
||||||
when :exactly then @expected_number == @matching_jobs_count
|
|
||||||
when :at_most then @expected_number >= @matching_jobs_count
|
|
||||||
when :at_least then @expected_number <= @matching_jobs_count
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def base_message
|
|
||||||
"#{message_expectation_modifier} #{@expected_number} jobs,".tap do |msg|
|
|
||||||
msg << " with #{@args}," if @args.any?
|
|
||||||
msg << " on queue #{@queue}," if @queue
|
|
||||||
msg << " at #{@at}," if @at
|
|
||||||
msg << " but enqueued #{@matching_jobs_count}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def serialized_attributes
|
|
||||||
{}.tap do |attributes|
|
|
||||||
attributes[:args] = ::ActiveJob::Arguments.serialize(@args) if @args.any?
|
|
||||||
attributes[:at] = @at.to_f if @at
|
|
||||||
attributes[:queue] = @queue if @queue
|
|
||||||
attributes[:job] = @job if @job
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_expected_number(relativity, count)
|
|
||||||
@expectation_type = relativity
|
|
||||||
@expected_number = case count
|
|
||||||
when :once then 1
|
|
||||||
when :twice then 2
|
|
||||||
when :thrice then 3
|
|
||||||
else Integer(count)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def queue_adapter
|
|
||||||
::ActiveJob::Base.queue_adapter
|
|
||||||
end
|
|
||||||
end
|
|
||||||
# rubocop: enable Style/ClassLength
|
|
||||||
|
|
||||||
# @private
|
|
||||||
class HaveEnqueuedJob < Base
|
|
||||||
def initialize(job)
|
|
||||||
super()
|
|
||||||
@job = job
|
|
||||||
end
|
|
||||||
|
|
||||||
def matches?(proc)
|
|
||||||
raise ArgumentError, "have_enqueued_job and enqueue_job only support block expectations" unless Proc === proc
|
|
||||||
|
|
||||||
original_enqueued_jobs_count = queue_adapter.enqueued_jobs.count
|
|
||||||
proc.call
|
|
||||||
in_block_jobs = queue_adapter.enqueued_jobs.drop(original_enqueued_jobs_count)
|
|
||||||
|
|
||||||
check(in_block_jobs)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# @private
|
|
||||||
class HaveBeenEnqueued < Base
|
|
||||||
def matches?(job)
|
|
||||||
@job = job
|
|
||||||
check(queue_adapter.enqueued_jobs)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# @api public
|
|
||||||
# Passes if a job has been enqueued inside block. May chain at_least, at_most or exactly to specify a number of times.
|
|
||||||
#
|
|
||||||
# @example
|
|
||||||
# expect {
|
|
||||||
# HeavyLiftingJob.perform_later
|
|
||||||
# }.to have_enqueued_job
|
|
||||||
#
|
|
||||||
# # Using alias
|
|
||||||
# expect {
|
|
||||||
# HeavyLiftingJob.perform_later
|
|
||||||
# }.to enqueue_job
|
|
||||||
#
|
|
||||||
# expect {
|
|
||||||
# HelloJob.perform_later
|
|
||||||
# HeavyLiftingJob.perform_later
|
|
||||||
# }.to have_enqueued_job(HelloJob).exactly(:once)
|
|
||||||
#
|
|
||||||
# expect {
|
|
||||||
# 3.times { HelloJob.perform_later }
|
|
||||||
# }.to have_enqueued_job(HelloJob).at_least(2).times
|
|
||||||
#
|
|
||||||
# expect {
|
|
||||||
# HelloJob.perform_later
|
|
||||||
# }.to have_enqueued_job(HelloJob).at_most(:twice)
|
|
||||||
#
|
|
||||||
# expect {
|
|
||||||
# HelloJob.perform_later
|
|
||||||
# HeavyLiftingJob.perform_later
|
|
||||||
# }.to have_enqueued_job(HelloJob).and have_enqueued_job(HeavyLiftingJob)
|
|
||||||
#
|
|
||||||
# expect {
|
|
||||||
# HelloJob.set(wait_until: Date.tomorrow.noon, queue: "low").perform_later(42)
|
|
||||||
# }.to have_enqueued_job.with(42).on_queue("low").at(Date.tomorrow.noon)
|
|
||||||
def have_enqueued_job(job = nil)
|
|
||||||
check_active_job_adapter
|
|
||||||
ActiveJob::HaveEnqueuedJob.new(job)
|
|
||||||
end
|
|
||||||
alias_method :enqueue_job, :have_enqueued_job
|
|
||||||
|
|
||||||
# @api public
|
|
||||||
# Passes if a job has been enqueued. May chain at_least, at_most or exactly to specify a number of times.
|
|
||||||
#
|
|
||||||
# @example
|
|
||||||
# before { ActiveJob::Base.queue_adapter.enqueued_jobs.clear }
|
|
||||||
#
|
|
||||||
# HeavyLiftingJob.perform_later
|
|
||||||
# expect(HeavyLiftingJob).to have_been_enqueued
|
|
||||||
#
|
|
||||||
# HelloJob.perform_later
|
|
||||||
# HeavyLiftingJob.perform_later
|
|
||||||
# expect(HeavyLiftingJob).to have_been_enqueued.exactly(:once)
|
|
||||||
#
|
|
||||||
# 3.times { HelloJob.perform_later }
|
|
||||||
# expect(HelloJob).to have_been_enqueued.at_least(2).times
|
|
||||||
#
|
|
||||||
# HelloJob.perform_later
|
|
||||||
# expect(HelloJob).to enqueue_job(HelloJob).at_most(:twice)
|
|
||||||
#
|
|
||||||
# HelloJob.perform_later
|
|
||||||
# HeavyLiftingJob.perform_later
|
|
||||||
# expect(HelloJob).to have_been_enqueued
|
|
||||||
# expect(HeavyLiftingJob).to have_been_enqueued
|
|
||||||
#
|
|
||||||
# HelloJob.set(wait_until: Date.tomorrow.noon, queue: "low").perform_later(42)
|
|
||||||
# expect(HelloJob).to have_been_enqueued.with(42).on_queue("low").at(Date.tomorrow.noon)
|
|
||||||
def have_been_enqueued
|
|
||||||
check_active_job_adapter
|
|
||||||
ActiveJob::HaveBeenEnqueued.new
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
# @private
|
|
||||||
def check_active_job_adapter
|
|
||||||
return if ::ActiveJob::QueueAdapters::TestAdapter === ::ActiveJob::Base.queue_adapter
|
|
||||||
raise StandardError, "To use ActiveJob matchers set `ActiveJob::Base.queue_adapter = :test`"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -5,10 +5,13 @@ RSpec.describe 'admin/billing/prices/_form' do
|
||||||
let(:price) { build_stubbed(:price) }
|
let(:price) { build_stubbed(:price) }
|
||||||
|
|
||||||
before :example do
|
before :example do
|
||||||
allow(view).to receive(:price).and_return(price)
|
without_partial_double_verification do
|
||||||
allow(view).to receive(:zones).and_return([])
|
allow(view).to receive(:price).and_return(price)
|
||||||
allow(view).to receive(:operation_categories).and_return([])
|
allow(view).to receive(:zones).and_return([])
|
||||||
allow(view).to receive(:durations).and_return([])
|
allow(view).to receive(:operation_categories).and_return([])
|
||||||
|
allow(view).to receive(:durations).and_return([])
|
||||||
|
end
|
||||||
|
|
||||||
stub_template '_form_errors' => ''
|
stub_template '_form_errors' => ''
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,10 @@ RSpec.describe 'admin/domains/edit' do
|
||||||
|
|
||||||
before :example do
|
before :example do
|
||||||
allow(DomainPresenter).to receive(:new).and_return(domain_presenter)
|
allow(DomainPresenter).to receive(:new).and_return(domain_presenter)
|
||||||
allow(view).to receive(:force_delete_templates)
|
|
||||||
|
without_partial_double_verification do
|
||||||
|
allow(view).to receive(:force_delete_templates)
|
||||||
|
end
|
||||||
|
|
||||||
assign(:domain, domain)
|
assign(:domain, domain)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,9 @@ RSpec.shared_examples 'domain mailer registrant info' do
|
||||||
let(:registrant) { instance_spy(RegistrantPresenter) }
|
let(:registrant) { instance_spy(RegistrantPresenter) }
|
||||||
|
|
||||||
before :example do
|
before :example do
|
||||||
allow(view).to receive(:registrant).and_return(registrant)
|
without_partial_double_verification do
|
||||||
|
allow(view).to receive(:registrant).and_return(registrant)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
attributes = %i(
|
attributes = %i(
|
||||||
|
|
|
@ -4,7 +4,9 @@ RSpec.shared_examples 'domain mailer registrar info' do
|
||||||
let(:registrar) { instance_spy(RegistrarPresenter) }
|
let(:registrar) { instance_spy(RegistrarPresenter) }
|
||||||
|
|
||||||
before :example do
|
before :example do
|
||||||
allow(view).to receive(:registrar).and_return(registrar)
|
without_partial_double_verification do
|
||||||
|
allow(view).to receive(:registrar).and_return(registrar)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
attributes = %i(
|
attributes = %i(
|
||||||
|
|
|
@ -4,7 +4,10 @@ RSpec.describe 'registrar/contacts/_form' do
|
||||||
let(:contact) { instance_spy(Depp::Contact) }
|
let(:contact) { instance_spy(Depp::Contact) }
|
||||||
|
|
||||||
before :example do
|
before :example do
|
||||||
allow(view).to receive(:f).and_return(ActionView::Helpers::FormBuilder.new(:contact, contact, view, {}))
|
without_partial_double_verification do
|
||||||
|
allow(view).to receive(:f).and_return(ActionView::Helpers::FormBuilder.new(:contact, contact, view, {}))
|
||||||
|
end
|
||||||
|
|
||||||
assign(:contact, contact)
|
assign(:contact, contact)
|
||||||
|
|
||||||
stub_template 'registrar/shared/_error_messages' => ''
|
stub_template 'registrar/shared/_error_messages' => ''
|
||||||
|
@ -16,7 +19,9 @@ RSpec.describe 'registrar/contacts/_form' do
|
||||||
|
|
||||||
context 'when address processing is enabled' do
|
context 'when address processing is enabled' do
|
||||||
before do
|
before do
|
||||||
allow(view).to receive(:address_processing?).and_return(true)
|
without_partial_double_verification do
|
||||||
|
allow(view).to receive(:address_processing?).and_return(true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has address' do
|
it 'has address' do
|
||||||
|
@ -27,7 +32,9 @@ RSpec.describe 'registrar/contacts/_form' do
|
||||||
|
|
||||||
context 'when address processing is disabled' do
|
context 'when address processing is disabled' do
|
||||||
before do
|
before do
|
||||||
allow(view).to receive(:address_processing?).and_return(false)
|
without_partial_double_verification do
|
||||||
|
allow(view).to receive(:address_processing?).and_return(false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has no address' do
|
it 'has no address' do
|
||||||
|
|
|
@ -4,7 +4,10 @@ RSpec.describe 'registrar/contacts/form/_legal_document' do
|
||||||
let(:contact) { instance_spy(Depp::Contact) }
|
let(:contact) { instance_spy(Depp::Contact) }
|
||||||
|
|
||||||
before :example do
|
before :example do
|
||||||
allow(view).to receive(:f).and_return(DefaultFormBuilder.new(:depp_contact, contact, view, {}))
|
without_partial_double_verification do
|
||||||
|
allow(view).to receive(:f).and_return(DefaultFormBuilder.new(:depp_contact, contact, view, {}))
|
||||||
|
end
|
||||||
|
|
||||||
assign(:contact, contact)
|
assign(:contact, contact)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,10 @@ RSpec.describe 'registrar/domains/_form' do
|
||||||
let(:domain) { instance_spy(Depp::Domain) }
|
let(:domain) { instance_spy(Depp::Domain) }
|
||||||
|
|
||||||
before :example do
|
before :example do
|
||||||
allow(view).to receive(:f).and_return(DefaultFormBuilder.new(:domain, domain, view, {}))
|
without_partial_double_verification do
|
||||||
|
allow(view).to receive(:f).and_return(DefaultFormBuilder.new(:domain, domain, view, {}))
|
||||||
|
end
|
||||||
|
|
||||||
assign(:domain, domain)
|
assign(:domain, domain)
|
||||||
|
|
||||||
stub_template 'registrar/domains/form/_general' => ''
|
stub_template 'registrar/domains/form/_general' => ''
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue