Class: ConvenientService::RSpec::Matchers::Classes::CallChainNext
- Inherits:
-
Object
- Object
- ConvenientService::RSpec::Matchers::Classes::CallChainNext
- Includes:
- RSpec::Expectations, RSpec::Matchers, RSpec::Mocks::ExampleMethods
- Defined in:
- lib/convenient_service/rspec/matchers/classes/call_chain_next.rb
Overview
Instance Method Summary collapse
- #and_return(*args, &block) ⇒ ConvenientService::RSpec::Matchers::Classes::CallChainNext
- #and_return_its_value ⇒ ConvenientService::RSpec::Matchers::Classes::CallChainNext
- #description ⇒ String
- #does_not_match?(block_expectation) ⇒ Bool
- #failure_message ⇒ String
- #failure_message_when_negated ⇒ String
- #matches?(block_expectation) ⇒ Bool
- #on(method) ⇒ ConvenientService::RSpec::Matchers::Classes::CallChainNext
- #supports_block_expectations? ⇒ Boolean
- #with_any_arguments ⇒ ConvenientService::RSpec::Matchers::Classes::CallChainNext
- #with_arguments(*args, **kwargs, &block) ⇒ ConvenientService::RSpec::Matchers::Classes::CallChainNext
- #without_arguments ⇒ ConvenientService::RSpec::Matchers::Classes::CallChainNext
Instance Method Details
#and_return(*args, &block) ⇒ ConvenientService::RSpec::Matchers::Classes::CallChainNext
194 195 196 197 198 |
# File 'lib/convenient_service/rspec/matchers/classes/call_chain_next.rb', line 194 def and_return(*args, &block) chain[:and_return] = args.any? ? proc { args.first } : block self end |
#and_return_its_value ⇒ ConvenientService::RSpec::Matchers::Classes::CallChainNext
182 183 184 185 186 |
# File 'lib/convenient_service/rspec/matchers/classes/call_chain_next.rb', line 182 def and_return_its_value chain[:and_return_its_value] = true self end |
#description ⇒ String
119 120 121 |
# File 'lib/convenient_service/rspec/matchers/classes/call_chain_next.rb', line 119 def description "call `chain.next`" end |
#does_not_match?(block_expectation) ⇒ Bool
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/convenient_service/rspec/matchers/classes/call_chain_next.rb', line 74 def does_not_match?(block_expectation) @block_expectation = block_expectation value = nil ## # NOTE: `expect { value = block_expectation.call }.not_to change(method, :chain_called?).from(false).to(true)` raises the following error: # # NotImplementedError: # `expect { }.not_to change { }.to()` is not supported # # That is why `expect(method.chain_called?).to eq(false)` is introduced. # - https://github.com/rspec/rspec-expectations/blob/main/lib/rspec/matchers/built_in/change.rb#L50 # expect(method.chain_called?).to eq(false) expect { value = block_expectation.call }.not_to change(method, :chain_called?) if used_with_arguments? expect(method.chain_args).not_to eq(expected_args) expect(method.chain_kwargs).not_to eq(expected_kwargs) expect(method.chain_block).not_to eq(expected_block) end if used_and_return_its_value? expect(value).not_to eq(method.chain_value) end if used_and_return? expect(value).not_to eq(return_block.call(method.chain_value)) end true end |
#failure_message ⇒ String
126 127 128 |
# File 'lib/convenient_service/rspec/matchers/classes/call_chain_next.rb', line 126 def "expected to call `chain.next`" end |
#failure_message_when_negated ⇒ String
133 134 135 |
# File 'lib/convenient_service/rspec/matchers/classes/call_chain_next.rb', line 133 def "expected NOT to call `chain.next`" end |
#matches?(block_expectation) ⇒ Bool
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/convenient_service/rspec/matchers/classes/call_chain_next.rb', line 38 def matches?(block_expectation) @block_expectation = block_expectation value = nil expect { value = block_expectation.call }.to change(method, :chain_called?).from(false).to(true) if used_with_arguments? expect(method.chain_args).to eq(expected_args) expect(method.chain_kwargs).to eq(expected_kwargs) expect(method.chain_block).to eq(expected_block) end if used_and_return_its_value? expect(value).to eq(method.chain_value) end if used_and_return? expect(value).to eq(return_block.call(method.chain_value)) end true end |
#on(method) ⇒ ConvenientService::RSpec::Matchers::Classes::CallChainNext
141 142 143 144 145 146 147 |
# File 'lib/convenient_service/rspec/matchers/classes/call_chain_next.rb', line 141 def on(method) method.reset! chain[:method] = method self end |
#supports_block_expectations? ⇒ Boolean
112 113 114 |
# File 'lib/convenient_service/rspec/matchers/classes/call_chain_next.rb', line 112 def supports_block_expectations? true end |
#with_any_arguments ⇒ ConvenientService::RSpec::Matchers::Classes::CallChainNext
164 165 166 167 168 |
# File 'lib/convenient_service/rspec/matchers/classes/call_chain_next.rb', line 164 def with_any_arguments chain.delete(:with_arguments) self end |
#with_arguments(*args, **kwargs, &block) ⇒ ConvenientService::RSpec::Matchers::Classes::CallChainNext
155 156 157 158 159 |
# File 'lib/convenient_service/rspec/matchers/classes/call_chain_next.rb', line 155 def with_arguments(*args, **kwargs, &block) chain[:with_arguments] = {args: args, kwargs: kwargs, block: block} self end |
#without_arguments ⇒ ConvenientService::RSpec::Matchers::Classes::CallChainNext
173 174 175 176 177 |
# File 'lib/convenient_service/rspec/matchers/classes/call_chain_next.rb', line 173 def without_arguments chain[:with_arguments] = {args: [], kwargs: {}, block: nil} self end |