Module: InertiaRails::RSpec::MatcherFactory
- Defined in:
- lib/inertia_rails/rspec.rb
Class Method Summary collapse
- .define_exact_matcher(name, field) ⇒ Object
- .define_inertia_matcher(name, &validation_block) ⇒ Object
- .define_key_absent_matcher(name, field) ⇒ Object
- .define_partial_matcher(name, field) ⇒ Object
Class Method Details
.define_exact_matcher(name, field) ⇒ Object
43 44 45 46 47 |
# File 'lib/inertia_rails/rspec.rb', line 43 def define_exact_matcher(name, field) define_inertia_matcher(name) do |inertia, expected| Testing::Assertions.validate_exact_match(inertia, field, expected) end end |
.define_inertia_matcher(name, &validation_block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/inertia_rails/rspec.rb', line 15 def define_inertia_matcher(name, &validation_block) ::RSpec::Matchers.define(name) do |*matcher_args| match do |actual| @result = instance_exec(actual, *matcher_args, &validation_block) @result[:passed] end { @result[:message] } { @result[:negated_message] } end end |
.define_key_absent_matcher(name, field) ⇒ Object
49 50 51 52 53 |
# File 'lib/inertia_rails/rspec.rb', line 49 def define_key_absent_matcher(name, field) define_inertia_matcher(name) do |inertia, key| Testing::Assertions.validate_key_absent(inertia, field, key) end end |
.define_partial_matcher(name, field) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/inertia_rails/rspec.rb', line 27 def define_partial_matcher(name, field) ::RSpec::Matchers.define(name) do |expected = nil| match do |inertia| @result = if block_arg Testing::Assertions.validate_with_block(inertia, field, &block_arg) else Testing::Assertions.validate_partial_match(inertia, field, expected) end @result[:passed] end { @result[:message] } { @result[:negated_message] } end end |