expectation 1.1.0 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +5 -5
  2. data/lib/contracts.rb +8 -6
  3. data/lib/expectation/matcher.rb +20 -5
  4. data/lib/expectation/version.rb +21 -2
  5. data/lib/expectation.rb +3 -2
  6. data/test/contracts_test.rb +2 -2
  7. data/test/expection_test.rb +3 -3
  8. data/test/matching_test.rb +9 -1
  9. data/test/test_helper.rb +2 -2
  10. data/test/version_test.rb +10 -0
  11. metadata +5 -30
  12. data/test/coverage/assets/0.10.0/application.css +0 -799
  13. data/test/coverage/assets/0.10.0/application.js +0 -1707
  14. data/test/coverage/assets/0.10.0/colorbox/border.png +0 -0
  15. data/test/coverage/assets/0.10.0/colorbox/controls.png +0 -0
  16. data/test/coverage/assets/0.10.0/colorbox/loading.gif +0 -0
  17. data/test/coverage/assets/0.10.0/colorbox/loading_background.png +0 -0
  18. data/test/coverage/assets/0.10.0/favicon_green.png +0 -0
  19. data/test/coverage/assets/0.10.0/favicon_red.png +0 -0
  20. data/test/coverage/assets/0.10.0/favicon_yellow.png +0 -0
  21. data/test/coverage/assets/0.10.0/loading.gif +0 -0
  22. data/test/coverage/assets/0.10.0/magnify.png +0 -0
  23. data/test/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  24. data/test/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  25. data/test/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  26. data/test/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  27. data/test/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  28. data/test/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  29. data/test/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  30. data/test/coverage/assets/0.10.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  31. data/test/coverage/assets/0.10.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
  32. data/test/coverage/assets/0.10.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  33. data/test/coverage/assets/0.10.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
  34. data/test/coverage/assets/0.10.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
  35. data/test/coverage/assets/0.10.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  36. data/test/coverage/index.html +0 -72
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0e82b68f20c078cadb99ae70a9fe2d3f73288680
4
- data.tar.gz: 071efc275974c5a339a4f4178cdaf6dd042f398d
2
+ SHA256:
3
+ metadata.gz: fd26fdbaac868c56921c0b06bd78be417e6cc5bd43fc59294359ff45423038b0
4
+ data.tar.gz: 9219259ffe130aca8133e1782cf39f367515ec2d77191cf3bc55478655306679
5
5
  SHA512:
6
- metadata.gz: 7cb4aa141fe72c1ca03c748add680c855b8c20e2b946386c3380a342515054fc8de7b32e8f5c32cc3e46f7a18ee1c9a0c16f4e816bed7503a146ad65f455d59b
7
- data.tar.gz: 6b9ebdad0ceadeb168cd26587a5ca0407b7e8c5151fa6daebced22366d0d1cd10ddee17033862ae2c612bf03c71ae4f82f6d33ea9d1c9f8474aafc8580fa1a01
6
+ metadata.gz: e3e700ce9a1ad71ce9a955e10a6a0741c2cd57fca8615e674d4def6ee254dc0b1c2dfd906a783cad5cd9d9dfb56295ae3061343043777ca0e326a9586740029f
7
+ data.tar.gz: 894475f57725b47289a0d40ee433b27c15746d9732bae78d976d99d15332c104be7c372331ab05d76efa217be29e11a77808ecfc033ac6192ccf17eba12eed27
data/lib/contracts.rb CHANGED
@@ -11,15 +11,17 @@
11
11
  #
12
12
  # We currently support the following annotations:
13
13
  #
14
- # - expects!
15
- # - returns!
14
+ # - +Expects
15
+ # - +Returns
16
+ # - +Nothrows
17
+ # - +Runtime
16
18
  #
17
19
  # == Example
18
20
  #
19
21
  # class Foo
20
22
  #
21
- # +Expects(value1: Fixnum, value2: /.@./)
22
- # +Returns(Fixnum)
23
+ # +Expects(value1: Integer, value2: /.@./)
24
+ # +Returns(Integer)
23
25
  #
24
26
  # def bar(value1, value2)
25
27
  # end
@@ -31,7 +33,7 @@ module Contracts
31
33
  class Error < ArgumentError; end
32
34
 
33
35
  (class << self; self; end).class_eval do
34
- attr :logger, true
36
+ attr_accessor :logger
35
37
  end
36
38
  self.logger = Logger.new(STDOUT)
37
39
 
@@ -149,7 +151,7 @@ module Contracts
149
151
  #
150
152
  # contains the method once the contract is initialized, which happens
151
153
  # in the Class#{singleton_,}method_added callback.
152
- attr :method, true
154
+ attr_accessor :method
153
155
 
154
156
  #
155
157
  # Returns a description of the method; i.e. Class#name or Class.name
@@ -8,6 +8,8 @@
8
8
  # The Expectation::Matcher module implements the logic to match a value
9
9
  # against a pattern.
10
10
 
11
+ require "uri"
12
+
11
13
  module Expectation::Matcher
12
14
  class Mismatch < ArgumentError
13
15
  attr_reader :value, :expectation, :info
@@ -21,8 +23,8 @@ module Expectation::Matcher
21
23
  def to_s
22
24
  message = "#{value.inspect} does not match #{expectation.inspect}"
23
25
  case info
24
- when nil then message
25
- when Fixnum then "#{message}, at index #{info}"
26
+ when nil then message
27
+ when Integer then "#{message}, at index #{info}"
26
28
  else "#{message}, at key #{info.inspect}"
27
29
  end
28
30
  end
@@ -52,19 +54,25 @@ module Expectation::Matcher
52
54
  when Array then
53
55
  if expectation.length == 1
54
56
  # Array as "array of elements matching an expectation"; for example
55
- # [1,2,3] => [Fixnum]
57
+ # [1,2,3] => [Integer]
56
58
  e = expectation.first
57
59
  value.each_with_index { |v, idx| match!(v, e, idx) }
58
60
  else
59
61
  # Array as "object matching one of given expectations
60
- expectation.any? { |e| _match?(value, e) }
62
+ expectation.any? { |exp| _match?(value, exp) }
61
63
  end
62
64
  when Proc then expectation.arity == 0 ? expectation.call : expectation.call(value)
63
65
  when Regexp then value.is_a?(String) && expectation =~ value
64
66
  when :__block then value.call
65
67
  when Hash then Hash === value &&
66
68
  expectation.each { |key, exp| match! value[key], exp, key }
67
- else expectation === value
69
+ when Module
70
+ if expectation == URI
71
+ _match_uri?(value)
72
+ else
73
+ expectation === value
74
+ end
75
+ else expectation === value
68
76
  end
69
77
 
70
78
  return if match
@@ -73,6 +81,13 @@ module Expectation::Matcher
73
81
 
74
82
  private
75
83
 
84
+ def _match_uri?(value)
85
+ URI.parse(value)
86
+ true
87
+ rescue URI::InvalidURIError
88
+ false
89
+ end
90
+
76
91
  def _match?(value, expectation)
77
92
  match! value, expectation
78
93
  true
@@ -4,6 +4,25 @@
4
4
  # License:: Distributes under the terms of the Modified BSD License,
5
5
  # see LICENSE.BSD for details.
6
6
  module Expectation
7
- # The expectation gem's version.
8
- VERSION = '1.1.0'
7
+ module GemHelper
8
+ extend self
9
+
10
+ def version(name)
11
+ spec = Gem.loaded_specs[name]
12
+ version = spec.version.to_s
13
+ version += "+unreleased" if unreleased?(spec)
14
+ version
15
+ end
16
+
17
+ private
18
+
19
+ def unreleased?(spec)
20
+ return false unless defined?(Bundler::Source::Gemspec)
21
+ return true if spec.source.is_a?(::Bundler::Source::Gemspec)
22
+ return true if spec.source.is_a?(::Bundler::Source::Path)
23
+ false
24
+ end
25
+ end
26
+
27
+ VERSION = GemHelper.version "expectation"
9
28
  end
data/lib/expectation.rb CHANGED
@@ -8,6 +8,7 @@
8
8
  module Expectation; end
9
9
 
10
10
  require_relative "core/exception"
11
+ require_relative "expectation/version"
11
12
  require_relative "expectation/matcher"
12
13
  require_relative "expectation/multi_matcher"
13
14
  require_relative "expectation/assertions"
@@ -57,7 +58,7 @@ module Expectation
57
58
  end
58
59
 
59
60
  def expect!(*args, &block)
60
- Expectation.expect! *args, &block
61
+ Expectation.expect!(*args, &block)
61
62
  rescue Expectation::Error
62
- $ERROR_INFO.reraise_with_current_backtrace!
63
+ $!.reraise_with_current_backtrace!
63
64
  end
@@ -125,7 +125,7 @@ class ContractsTest < Test::Unit::TestCase
125
125
  end
126
126
 
127
127
  class Foo
128
- +Expects(v: Fixnum)
128
+ +Expects(v: Integer)
129
129
  def throw_on_one(v)
130
130
  raise if v == 1
131
131
  end
@@ -155,7 +155,7 @@ class ContractsTest < Test::Unit::TestCase
155
155
  foo.wait_for 0.001
156
156
  foo.wait_for 0.02
157
157
 
158
- e = assert_raise(Contracts::Error) {
158
+ assert_raise(Contracts::Error) {
159
159
  foo.wait_for 10
160
160
  }
161
161
 
@@ -37,13 +37,13 @@ class ExpectationTest < Test::Unit::TestCase
37
37
  end
38
38
 
39
39
  def test_array_expectations
40
- assert_expectation! 1 => [Fixnum, String]
41
- assert_expectation! 1 => [String, Fixnum]
40
+ assert_expectation! 1 => [Integer, String]
41
+ assert_expectation! 1 => [String, Integer]
42
42
  assert_failed_expectation! 1 => [NilClass, String]
43
43
  end
44
44
 
45
45
  def test_multi_expectations
46
- assert_expectation! 1 => Fixnum | String
46
+ assert_expectation! 1 => Integer | String
47
47
  assert_expectation! 1 => String | 1
48
48
  assert_failed_expectation! 1 => NilClass | String
49
49
  assert_expectation! 1 => NilClass | String | 1
@@ -26,7 +26,7 @@ class MatchingTest < Test::Unit::TestCase
26
26
 
27
27
  def test_int_expectations
28
28
  assert_match 1, 1
29
- assert_match 1, Fixnum
29
+ assert_match 1, Integer
30
30
  assert_match 1, Integer
31
31
  assert_match 1, 0..2
32
32
  assert_match 1, 0..1
@@ -76,4 +76,12 @@ class MatchingTest < Test::Unit::TestCase
76
76
  assert_mismatch({ :key => "Foo" }, { :key => [Integer,"Bar"] })
77
77
  assert_match({ :other_key => "Foo" }, { :key => [nil, "Foo"] })
78
78
  end
79
+
80
+ def test_uri_expectations
81
+ assert_match "http://foo/bar", URI
82
+ assert_match "/foo/bar", URI
83
+ assert_mismatch " foo", URI
84
+ assert_mismatch nil, URI
85
+ assert_mismatch 1, URI
86
+ end
79
87
  end
data/test/test_helper.rb CHANGED
@@ -24,13 +24,13 @@ require "expectation"
24
24
  class Test::Unit::TestCase
25
25
  def assert_expectation!(*expectation, &block)
26
26
  assert_nothing_raised do
27
- expect! *expectation, &block
27
+ expect!(*expectation, &block)
28
28
  end
29
29
  end
30
30
 
31
31
  def assert_failed_expectation!(*expectation, &block)
32
32
  assert_raise(Expectation::Error) {
33
- expect! *expectation, &block
33
+ expect!(*expectation, &block)
34
34
  }
35
35
  end
36
36
  end
@@ -0,0 +1,10 @@
1
+ # Author:: radiospiel (mailto:eno@radiospiel.org)
2
+ # Copyright:: Copyright (c) 2011, 2012 radiospiel
3
+ # License:: Distributes under the terms of the Modified BSD License, see LICENSE.BSD for details.
4
+ require_relative 'test_helper'
5
+
6
+ class VersionTest < Test::Unit::TestCase
7
+ def test_returns_a_version
8
+ assert_match(/\d\.\d\.\d/,Expectation::VERSION)
9
+ end
10
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expectation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - radiospiel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-20 00:00:00.000000000 Z
11
+ date: 2022-07-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Defensive programming with expectations
14
14
  email: eno@radiospiel.org
@@ -32,35 +32,11 @@ files:
32
32
  - test/contracts_module_test.rb
33
33
  - test/contracts_singleton_test.rb
34
34
  - test/contracts_test.rb
35
- - test/coverage/assets/0.10.0/application.css
36
- - test/coverage/assets/0.10.0/application.js
37
- - test/coverage/assets/0.10.0/colorbox/border.png
38
- - test/coverage/assets/0.10.0/colorbox/controls.png
39
- - test/coverage/assets/0.10.0/colorbox/loading.gif
40
- - test/coverage/assets/0.10.0/colorbox/loading_background.png
41
- - test/coverage/assets/0.10.0/favicon_green.png
42
- - test/coverage/assets/0.10.0/favicon_red.png
43
- - test/coverage/assets/0.10.0/favicon_yellow.png
44
- - test/coverage/assets/0.10.0/loading.gif
45
- - test/coverage/assets/0.10.0/magnify.png
46
- - test/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
47
- - test/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
48
- - test/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
49
- - test/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
50
- - test/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png
51
- - test/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
52
- - test/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
53
- - test/coverage/assets/0.10.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png
54
- - test/coverage/assets/0.10.0/smoothness/images/ui-icons_222222_256x240.png
55
- - test/coverage/assets/0.10.0/smoothness/images/ui-icons_2e83ff_256x240.png
56
- - test/coverage/assets/0.10.0/smoothness/images/ui-icons_454545_256x240.png
57
- - test/coverage/assets/0.10.0/smoothness/images/ui-icons_888888_256x240.png
58
- - test/coverage/assets/0.10.0/smoothness/images/ui-icons_cd0a0a_256x240.png
59
- - test/coverage/index.html
60
35
  - test/exception_extension_test.rb
61
36
  - test/expection_test.rb
62
37
  - test/matching_test.rb
63
38
  - test/test_helper.rb
39
+ - test/version_test.rb
64
40
  homepage: http://github.com/radiospiel/expectation
65
41
  licenses: []
66
42
  metadata: {}
@@ -72,15 +48,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
48
  requirements:
73
49
  - - ">="
74
50
  - !ruby/object:Gem::Version
75
- version: '0'
51
+ version: '2.5'
76
52
  required_rubygems_version: !ruby/object:Gem::Requirement
77
53
  requirements:
78
54
  - - ">="
79
55
  - !ruby/object:Gem::Version
80
56
  version: '0'
81
57
  requirements: []
82
- rubyforge_project:
83
- rubygems_version: 2.4.6
58
+ rubygems_version: 3.1.4
84
59
  signing_key:
85
60
  specification_version: 4
86
61
  summary: Defensive programming with expectations