Class: Matest::ExampleGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/matest.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope_block) ⇒ ExampleGroup

Returns a new instance of ExampleGroup.



90
91
92
93
94
95
# File 'lib/matest.rb', line 90

def initialize(scope_block)
  @scope_block = scope_block
  @specs       = []
  @lets        = []
  @statuses    = []
end

Instance Attribute Details

#letsObject (readonly)

Returns the value of attribute lets.



87
88
89
# File 'lib/matest.rb', line 87

def lets
  @lets
end

#scope_blockObject (readonly)

Returns the value of attribute scope_block.



85
86
87
# File 'lib/matest.rb', line 85

def scope_block
  @scope_block
end

#specsObject (readonly)

Returns the value of attribute specs.



86
87
88
# File 'lib/matest.rb', line 86

def specs
  @specs
end

#statusesObject (readonly)

Returns the value of attribute statuses.



88
89
90
# File 'lib/matest.rb', line 88

def statuses
  @statuses
end

Class Method Details

.let(var_name, &block) ⇒ Object



120
121
122
123
124
# File 'lib/matest.rb', line 120

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



102
103
104
105
106
107
108
109
# File 'lib/matest.rb', line 102

def execute!
  instance_eval(&scope_block)
  specs.shuffle.each do |spec, desc|
    res = run_spec(spec)
    print res
  end

end

#let(var_name, and_call = false, &block) ⇒ Object



126
127
128
# File 'lib/matest.rb', line 126

def let(var_name, and_call=false, &block)
  lets << Let.new(var_name, block, and_call=false)
end

#let!(var_name, &block) ⇒ Object



130
131
132
# File 'lib/matest.rb', line 130

def let!(var_name, &block)
  lets << Let.new(var_name, block, and_call=true)
end

#run_spec(spec) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/matest.rb', line 134

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

#spec(description = nil, &block) ⇒ Object



97
98
99
100
# File 'lib/matest.rb', line 97

def spec(description=nil, &block)
  current_example = block_given? ? block : -> { Matest::SkipMe.new }
  specs << Example.new(current_example, description, lets)
end

#xspec(description = nil, &block) ⇒ Object



111
112
113
# File 'lib/matest.rb', line 111

def xspec(description=nil, &block)
  spec(description)
end