Module: TestBench::Fixture
- Includes:
- Session::Events
- Included in:
- Controls::Fixture::Class::Actuator, Controls::Fixture::Class::BuildMethod, Controls::Fixture::Class::NoBuildMethod, Controls::Fixture::Class::TestBlock, Controls::Fixture::Class::TestBlock::BuildMethod, Controls::Fixture::Example, Evaluate
- Defined in:
- lib/test_bench/fixture/fixture.rb,
lib/test_bench/fixture/evaluate.rb,
lib/test_bench/fixture/actuate/class.rb,
lib/test_bench/fixture/actuate/object.rb,
lib/test_bench/fixture/controls/title.rb,
lib/test_bench/fixture/controls/output.rb,
lib/test_bench/fixture/controls/random.rb,
lib/test_bench/fixture/controls/result.rb,
lib/test_bench/fixture/controls/fixture.rb,
lib/test_bench/fixture/controls/exception.rb,
lib/test_bench/fixture/controls/fixture/class.rb,
lib/test_bench/fixture/controls/fixture/object.rb,
lib/test_bench/fixture/controls/fixture/object/modules.rb
Defined Under Namespace
Modules: Actuate, Controls Classes: Evaluate
Instance Attribute Summary collapse
Class Method Summary collapse
- .call(fixture_class_or_object) ⇒ Object
- .comment(telemetry, event_class, text, *additional_texts, heading: nil, quote: nil) ⇒ Object
- .output(fixture, styling: nil) ⇒ Object
Instance Method Summary collapse
- #assert(result) ⇒ Object
- #assert_raises(exception_class = nil, message = nil, strict: nil, &block) ⇒ Object
- #comment ⇒ Object
- #context(title = nil, &block) ⇒ Object
- #context!(title = nil, &block) ⇒ Object
- #detail ⇒ Object
- #fail!(message = nil) ⇒ Object
- #fixture(fixture_class_or_object) ⇒ Object
- #fixture_passed? ⇒ Boolean (also: #passed?)
- #refute(result) ⇒ Object
- #refute_raises(exception_class = nil, strict: nil, &block) ⇒ Object
- #test(title = nil, &block) ⇒ Object
- #test!(title = nil, &block) ⇒ Object
Instance Attribute Details
#test_session ⇒ Object
5 6 7 |
# File 'lib/test_bench/fixture/fixture.rb', line 5 def test_session @test_session ||= Session::Substitute.build end |
Class Method Details
.call(fixture_class_or_object) ⇒ Object
189 190 191 192 193 194 195 196 197 |
# File 'lib/test_bench/fixture/fixture.rb', line 189 def self.call(fixture_class_or_object, ...) if fixture_class_or_object.instance_of?(Class) fixture_class = fixture_class_or_object Actuate::Class.(fixture_class, ...) else object = fixture_class_or_object Actuate::Object.(object, ...) end end |
.comment(telemetry, event_class, text, *additional_texts, heading: nil, quote: nil) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/test_bench/fixture/fixture.rb', line 140 def self.comment(telemetry, event_class, text, *additional_texts, heading: nil, quote: nil) texts = [text, *additional_texts] texts.map! do |text| text.to_str end if quote.nil? quote = texts.last.end_with?("\n") end if quote if heading.nil? heading = !text.end_with?("\n") end end if heading heading = texts.shift else heading = nil end if quote text = texts.join else text = texts.first end event = event_class.new event.text = text event.quote = quote event.heading = heading telemetry.record(event) if not quote texts[1..-1].each do |text| comment(telemetry, event_class, text, heading: false, quote: false) end end end |
.output(fixture, styling: nil) ⇒ Object
183 184 185 186 187 |
# File 'lib/test_bench/fixture/fixture.rb', line 183 def self.output(fixture, styling: nil) session = fixture.test_session TestBench::Session::Output::Get.(session, styling:) end |
Instance Method Details
#assert(result) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/test_bench/fixture/fixture.rb', line 23 def assert(result) if not [true, false, nil].include?(result) raise TypeError, "Value #{result.inspect} isn't a boolean" end result = false if result.nil? test_session.assert(result) end |
#assert_raises(exception_class = nil, message = nil, strict: nil, &block) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/test_bench/fixture/fixture.rb', line 43 def assert_raises(exception_class=nil, =nil, strict: nil, &block) if exception_class.nil? strict ||= false exception_class = StandardError else strict = true if strict.nil? end detail "Expected exception: #{exception_class}#{' (strict)' if strict}" if not .nil? detail "Expected message: #{.inspect}" end block.() detail "(No exception was raised)" rescue exception_class => exception detail "Raised exception: #{exception.inspect}#{" (subclass of #{exception_class})" if exception.class < exception_class}" if strict && !exception.instance_of?(exception_class) raise exception end if .nil? result = true else result = exception. == end assert(result) else assert(false) end |
#comment ⇒ Object
15 16 17 |
# File 'lib/test_bench/fixture/fixture.rb', line 15 def comment(...) Fixture.comment(test_session.telemetry, Commented, ...) end |
#context(title = nil, &block) ⇒ Object
106 107 108 109 110 |
# File 'lib/test_bench/fixture/fixture.rb', line 106 def context(title=nil, &block) title = title&.to_str test_session.context(title, &block) end |
#context!(title = nil, &block) ⇒ Object
112 113 114 115 116 |
# File 'lib/test_bench/fixture/fixture.rb', line 112 def context!(title=nil, &block) title = title&.to_str test_session.context!(title, &block) end |
#detail ⇒ Object
19 20 21 |
# File 'lib/test_bench/fixture/fixture.rb', line 19 def detail(...) Fixture.comment(test_session.telemetry, Detailed, ...) end |
#fail!(message = nil) ⇒ Object
130 131 132 |
# File 'lib/test_bench/fixture/fixture.rb', line 130 def fail!(=nil) test_session.fail() end |
#fixture(fixture_class_or_object) ⇒ Object
134 135 136 137 138 |
# File 'lib/test_bench/fixture/fixture.rb', line 134 def fixture(fixture_class_or_object, *, **, &) session = self.test_session Fixture.(fixture_class_or_object, *, session:, **, &) end |
#fixture_passed? ⇒ Boolean Also known as: passed?
10 11 12 |
# File 'lib/test_bench/fixture/fixture.rb', line 10 def fixture_passed? test_session.passed? end |
#refute(result) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/test_bench/fixture/fixture.rb', line 33 def refute(result) if not [true, false, nil].include?(result) raise TypeError, "Value #{result.inspect} isn't a boolean" end negated_result = !result test_session.assert(negated_result) end |
#refute_raises(exception_class = nil, strict: nil, &block) ⇒ Object
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 |
# File 'lib/test_bench/fixture/fixture.rb', line 79 def refute_raises(exception_class=nil, strict: nil, &block) if exception_class.nil? strict ||= false exception_class = StandardError else strict = true if strict.nil? end detail "Prohibited exception: #{exception_class}#{' (strict)' if strict}" block.() detail "(No exception was raised)" rescue exception_class => exception detail "Raised exception: #{exception.inspect}#{" (subclass of #{exception_class})" if exception.class < exception_class}" if strict && !exception.instance_of?(exception_class) raise exception end assert(false) else assert(true) end |
#test(title = nil, &block) ⇒ Object
118 119 120 121 122 |
# File 'lib/test_bench/fixture/fixture.rb', line 118 def test(title=nil, &block) title = title&.to_str test_session.test(title, &block) end |
#test!(title = nil, &block) ⇒ Object
124 125 126 127 128 |
# File 'lib/test_bench/fixture/fixture.rb', line 124 def test!(title=nil, &block) title = title&.to_str test_session.test!(title, &block) end |