invoca-utils 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60e1c062370766eca1fa617f36be49862eaf88ac
4
- data.tar.gz: e459f4db3a562dd66d965f781471931b69721f22
3
+ metadata.gz: 803af8a0e5807bf4ff18c6d9f3ab1d300dd35b4c
4
+ data.tar.gz: 05f62242e46f4804eabbcd80a13d8e8ce31f3e1f
5
5
  SHA512:
6
- metadata.gz: 13f0207b9e47f0197970d027c6ce5956a8513f9cc4d6771a880470d57ef0bc0f54cc851b3220d683b98025790d49ff2f05c21a19c34e1ce4887073c10f83ea0f
7
- data.tar.gz: 917afbc8c609b0361cc3a5e1c373c7164de6b2350c6f2209ca3ede0288393c9c3b8d4e02e50625b85bd89973302e15fe0559f570af9cd4846d8c907c94126bcd
6
+ metadata.gz: 239abcd4639fe9964477283066f852fea8d4c45f1bd97b08830239d81b11fe8392cfd52b0fc9505779e8a51e3ff9b1e9a1298d4cdd9f811365f782dc37ffd77f
7
+ data.tar.gz: 478e3b36bb18e5df962bb9fd258d7aaca49e908965c7b775a4a64806fe5f87019d89e595d5d945c7aaf3d9030b30d6ebeee63a0f98ea41d53c9213193593e6cd
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Invoca::Utils
2
2
 
3
- A public collection of helpers used in multiple project.
3
+ A public collection of helpers used in multiple projects
4
4
 
5
5
  ## Installation
6
6
 
@@ -1,7 +1,6 @@
1
1
  require "invoca/utils/version"
2
2
 
3
3
  require "invoca/utils/diff"
4
- require "invoca/utils/log_error_stub"
5
4
 
6
5
  module Invoca
7
6
  module Utils
@@ -1,5 +1,5 @@
1
1
  module Invoca
2
2
  module Utils
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invoca-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cary Penniman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-01 00:00:00.000000000 Z
11
+ date: 2014-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -137,7 +137,6 @@ files:
137
137
  - invoca-utils.gemspec
138
138
  - lib/invoca/utils.rb
139
139
  - lib/invoca/utils/diff.rb
140
- - lib/invoca/utils/log_error_stub.rb
141
140
  - lib/invoca/utils/version.rb
142
141
  - test/test_helper.rb
143
142
  - test/unit/utils_test.rb
@@ -1,84 +0,0 @@
1
- #
2
- # Used by functional tests to track exceptions.
3
- #
4
-
5
- module LogErrorStub
6
- class UnexpectedExceptionLogged < StandardError; end
7
- class ExpectedExceptionNotLogged < StandardError; end
8
-
9
- def setup_log_error_stub
10
- clear_exception_whitelist
11
- stub_log_error unless respond_to?(:dont_stub_log_error) && dont_stub_log_error
12
- end
13
-
14
- def teardown_log_error_stub
15
- ExceptionHandling.stub_handler = nil
16
- return unless @exception_whitelist
17
- @exception_whitelist.each do |item|
18
- add_failure("log_error expected #{item[1][:expected]} times with pattern: '#{item[0].is_a?(Regexp) ? item[0].source : item[0]}' #{item[1][:count]} found #{item[1][:found]}") unless item[1][:expected] == item[1][:found]
19
- end
20
- end
21
-
22
- attr_accessor :exception_whitelist
23
-
24
- #
25
- # Call this function in your functional tests - usually first line after a "should" statement
26
- # once called, you can then call expects_exception
27
- # By stubbing log error, ExceptionHandling will keep a list of all expected exceptions and
28
- # gracefully note their occurrence.
29
- #
30
- def stub_log_error
31
- ExceptionHandling.stub_handler = self
32
- end
33
-
34
- #
35
- # Gets called by ExceptionHandling::log_error in test mode.
36
- # If you have called expects_exception then this function will simply note that an
37
- # instance of that exception has occurred - otherwise it will raise (which will
38
- # generally result in a 500 return code for your test request)
39
- #
40
- def handle_stub_log_error(exception_data, always_raise = false)
41
- raise_unexpected_exception(exception_data) if always_raise || !exception_filtered?(exception_data)
42
- end
43
-
44
- #
45
- # Did the calling code call expects_exception on this exception?
46
- #
47
- def exception_filtered?(exception_data)
48
- @exception_whitelist && @exception_whitelist.any? do |expectation|
49
- if expectation[0] === exception_data[:error]
50
- expectation[1][:found] += 1
51
- true
52
- end
53
- end
54
- end
55
-
56
- #
57
- # Call this from your test file to declare what exceptions you expect to raise.
58
- #
59
- def expects_exception(pattern, options = {})
60
- @exception_whitelist ||= []
61
- expected_count = options[:count] || 1
62
- options = {:expected => expected_count, :found => 0}
63
- if to_increment = @exception_whitelist.find {|ex| ex[0] == pattern}
64
- to_increment[1][:expected] += expected_count
65
- else
66
- @exception_whitelist << [pattern, options]
67
- end
68
- end
69
-
70
- def clear_exception_whitelist
71
- @exception_whitelist = nil
72
- end
73
-
74
- private
75
-
76
- def raise_unexpected_exception(exception_data)
77
- raise(UnexpectedExceptionLogged,
78
- exception_data[:error] + "\n" +
79
- "---original backtrace---\n" +
80
- exception_data[:backtrace].join("\n") + "\n" +
81
- "------")
82
- end
83
-
84
- end