Class: Funktional::AssignedAssertion
- Inherits:
-
Object
- Object
- Funktional::AssignedAssertion
- Defined in:
- lib/funktional/assigned_assertion.rb
Instance Method Summary collapse
-
#initialize(klass_or_symbol) ⇒ AssignedAssertion
constructor
A new instance of AssignedAssertion.
- #should_be(expected_value = nil, &block) ⇒ Object
Constructor Details
#initialize(klass_or_symbol) ⇒ AssignedAssertion
Returns a new instance of AssignedAssertion.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/funktional/assigned_assertion.rb', line 3 def initialize(klass_or_symbol) if klass_or_symbol.is_a? Symbol @symbol = klass_or_symbol else @klass = klass_or_symbol @symbol = get_symbol_from_klass end @test = Funktional.test_instance @assigned = @test.assigns(@symbol) @test.assert_not_nil @assigned, "No [#{@symbol}] assigned" if @klass @test.assert @assigned.is_a?(@klass), type_safety_failed_msg end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object (protected)
31 32 33 |
# File 'lib/funktional/assigned_assertion.rb', line 31 def method_missing(method, *args) RecursiveAssertion.new(@assigned, method) end |
Instance Method Details
#should_be(expected_value = nil, &block) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/funktional/assigned_assertion.rb', line 21 def should_be(expected_value=nil, &block) if block_given? expected_value ||= block.bind(@test).call end @test.assert_equal expected_value, @assigned end |