Class: Matest::ExampleGroup
- Inherits:
-
Object
- Object
- Matest::ExampleGroup
- Defined in:
- lib/matest/example_group.rb
Instance Attribute Summary collapse
-
#lets ⇒ Object
readonly
Returns the value of attribute lets.
-
#printer ⇒ Object
Returns the value of attribute printer.
-
#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, bang = false, &block) ⇒ Object
- #let!(var_name, &block) ⇒ Object
- #run_spec(spec) ⇒ Object
- #spec(description = nil, &block) ⇒ Object (also: #it, #test, #example)
- #xspec(description = nil, &block) ⇒ Object (also: #xit, #xtest, #xexample)
Constructor Details
#initialize(scope_block) ⇒ ExampleGroup
Returns a new instance of ExampleGroup.
10 11 12 13 14 15 |
# File 'lib/matest/example_group.rb', line 10 def initialize(scope_block) @scope_block = scope_block @specs = [] @lets = [] @statuses = [] end |
Instance Attribute Details
#lets ⇒ Object (readonly)
Returns the value of attribute lets.
5 6 7 |
# File 'lib/matest/example_group.rb', line 5 def lets @lets end |
#printer ⇒ Object
Returns the value of attribute printer.
8 9 10 |
# File 'lib/matest/example_group.rb', line 8 def printer @printer end |
#scope_block ⇒ Object (readonly)
Returns the value of attribute scope_block.
3 4 5 |
# File 'lib/matest/example_group.rb', line 3 def scope_block @scope_block end |
#specs ⇒ Object (readonly)
Returns the value of attribute specs.
4 5 6 |
# File 'lib/matest/example_group.rb', line 4 def specs @specs end |
#statuses ⇒ Object (readonly)
Returns the value of attribute statuses.
6 7 8 |
# File 'lib/matest/example_group.rb', line 6 def statuses @statuses end |
Class Method Details
.let(var_name, &block) ⇒ Object
45 46 47 48 49 |
# File 'lib/matest/example_group.rb', line 45 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
27 28 29 30 31 32 33 34 |
# File 'lib/matest/example_group.rb', line 27 def execute! instance_eval(&scope_block) specs.shuffle.each do |spec, desc| res = run_spec(spec) printer.prints(res) end end |
#let(var_name, bang = false, &block) ⇒ Object
51 52 53 |
# File 'lib/matest/example_group.rb', line 51 def let(var_name, bang=false, &block) lets << Let.new(var_name, block, bang=false) end |
#let!(var_name, &block) ⇒ Object
55 56 57 |
# File 'lib/matest/example_group.rb', line 55 def let!(var_name, &block) lets << Let.new(var_name, block, bang=true) end |
#run_spec(spec) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/matest/example_group.rb', line 59 def run_spec(spec) 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) rescue Exception => e Matest::ExceptionRaised.new(spec, e, spec.description) end @statuses << status status end |