exemplor 2010.1.0 → 2010.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2010.1.0
1
+ 2010.2.0
@@ -46,6 +46,7 @@ eg { check_output_matches_expected_for :assertion_success }
46
46
  eg { check_output_matches_expected_for :assertion_failure }
47
47
  eg { check_output_matches_expected_for :assertion_success_and_failure }
48
48
  eg { check_output_matches_expected_for :assertion_success_and_info }
49
+ eg { check_output_matches_expected_for :failure_halts_execution }
49
50
  eg { check_output_matches_expected_for :helpers }
50
51
  eg { check_output_matches_expected_for :with_setup }
51
52
  eg { check_output_matches_expected_for :checking_nil }
@@ -0,0 +1,17 @@
1
+ require 'exemplor'
2
+
3
+ eg 'Failures halt execution' do
4
+ list = [1, 2, 3]
5
+ Check(list.first).is(1_000_000) # fail!
6
+ raise "foo" # we never get here
7
+ end
8
+
9
+ __END__
10
+
11
+ - name: Failures halt execution
12
+ status: failure
13
+ result:
14
+ - name: list.first
15
+ status: failure
16
+ expected: 1000000
17
+ actual: 1
@@ -18,9 +18,13 @@ module Exemplor
18
18
  @name + (defined?(@disambiguate) ? " #{@disambiguate}" : '')
19
19
  end
20
20
 
21
+ # might be better to use throw here
22
+ class Failure < StandardError; end
23
+
21
24
  def is(expectation)
22
25
  @expectation = expectation
23
26
  @status = (value == expectation) ? :success : :failure
27
+ raise Failure if failure?
24
28
  end
25
29
 
26
30
  def success?
@@ -18,10 +18,14 @@ module Exemplor
18
18
 
19
19
  env.instance_eval(&self.setup_block) if self.setup_block
20
20
  value = env.instance_eval(&code)
21
- result = env._status == :info ?
22
- render_value(value) : render_checks(env._checks)
23
- [env._status, result]
21
+ if env._checks.empty?
22
+ [:info, render_value(value)]
23
+ else # :infos or :success
24
+ [env._status, render_checks(env._checks)]
25
+ end
24
26
 
27
+ rescue Check::Failure => failure
28
+ [:failure, render_checks(env._checks)]
25
29
  rescue Object => error
26
30
  [:error, render_error(error)]
27
31
  ensure
@@ -99,8 +103,6 @@ module Exemplor
99
103
  end
100
104
 
101
105
  def _status
102
- (:info if _checks.empty?) ||
103
- (:failure if _checks.any? { |c| c.failure? }) ||
104
106
  (:success if _checks.all? { |c| c.success? }) ||
105
107
  :infos
106
108
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 2010
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 2010.1.0
9
+ version: 2010.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Myles Byrne
@@ -70,6 +70,7 @@ files:
70
70
  - examples/check_with_disambiguation.rb
71
71
  - examples/checking_nil.rb
72
72
  - examples/dumping_classes.rb
73
+ - examples/failure_halts_execution.rb
73
74
  - examples/helpers.rb
74
75
  - examples/no_checks.rb
75
76
  - examples/no_checks_non_string.rb
@@ -124,6 +125,7 @@ test_files:
124
125
  - examples/check_with_disambiguation.rb
125
126
  - examples/checking_nil.rb
126
127
  - examples/dumping_classes.rb
128
+ - examples/failure_halts_execution.rb
127
129
  - examples/helpers.rb
128
130
  - examples/no_checks.rb
129
131
  - examples/no_checks_non_string.rb