Class: Matest::ExampleGroup
- Inherits:
-
Object
- Object
- Matest::ExampleGroup
- Defined in:
- lib/matest.rb
Instance Attribute Summary collapse
-
#scope_block ⇒ Object
readonly
Returns the value of attribute scope_block.
-
#specs ⇒ Object
readonly
Returns the value of attribute specs.
-
#statuses ⇒ Object
readonly
Returns the value of attribute statuses.
Class Method Summary collapse
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(scope_block) ⇒ ExampleGroup
constructor
A new instance of ExampleGroup.
- #let(var_name, &block) ⇒ Object
- #let!(var_name, &block) ⇒ Object
- #run_spec(spec, description) ⇒ Object
- #spec(description = nil, &block) ⇒ Object
- #xspec(description = nil, &block) ⇒ Object
Constructor Details
#initialize(scope_block) ⇒ ExampleGroup
Returns a new instance of ExampleGroup.
136 137 138 139 140 |
# File 'lib/matest.rb', line 136 def initialize(scope_block) @scope_block = scope_block @specs = [] @statuses = [] end |
Instance Attribute Details
#scope_block ⇒ Object (readonly)
Returns the value of attribute scope_block.
132 133 134 |
# File 'lib/matest.rb', line 132 def scope_block @scope_block end |
#specs ⇒ Object (readonly)
Returns the value of attribute specs.
133 134 135 |
# File 'lib/matest.rb', line 133 def specs @specs end |
#statuses ⇒ Object (readonly)
Returns the value of attribute statuses.
134 135 136 |
# File 'lib/matest.rb', line 134 def statuses @statuses end |
Class Method Details
.let(var_name, &block) ⇒ Object
165 166 167 168 169 |
# File 'lib/matest.rb', line 165 def self.let(var_name, &block) define_method(var_name) do instance_variable_set(:"@#{var_name}", block.call) end end |
Instance Method Details
#execute! ⇒ Object
142 143 144 145 146 147 148 149 |
# File 'lib/matest.rb', line 142 def execute! instance_eval(&scope_block) specs.shuffle.each do |spec, desc| res = run_spec(spec, desc) print res end end |
#let(var_name, &block) ⇒ Object
171 172 173 |
# File 'lib/matest.rb', line 171 def let(var_name, &block) self.class.let(var_name, &block) end |
#let!(var_name, &block) ⇒ Object
175 176 177 178 |
# File 'lib/matest.rb', line 175 def let!(var_name, &block) self.class.let(var_name, &block) send(var_name) end |
#run_spec(spec, description) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/matest.rb', line 180 def run_spec(spec, description) status = begin result = spec.call status_class = case result when true Matest::SpecPassed when false Matest::SpecFailed when Matest::SkipMe Matest::SpecSkipped else Matest::NotANaturalAssertion end status_class.new(spec, result, description) rescue Exception => e Matest::ExceptionRaised.new(spec, e, description) end @statuses << status status end |
#spec(description = nil, &block) ⇒ Object
151 152 153 154 |
# File 'lib/matest.rb', line 151 def spec(description=nil, &block) current_example = block_given? ? block : -> { Matest::SkipMe.new } specs << [current_example, description] end |
#xspec(description = nil, &block) ⇒ Object
156 157 158 |
# File 'lib/matest.rb', line 156 def xspec(description=nil, &block) spec(description) end |