peck 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -0
  3. data/lib/peck.rb +2 -2
  4. data/lib/peck/expectations.rb +29 -15
  5. metadata +10 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53dc1c47e6cacb7a91a7a6bee9c92e6bf0c25f4d
4
- data.tar.gz: 38d1273aef3190dcaa77ad9d5d95df1798a35448
3
+ metadata.gz: 31e84323777923757ea92ec4f0f17108284c8e3d
4
+ data.tar.gz: 180a784bb795075f2bc9815e734aba538d2e7850
5
5
  SHA512:
6
- metadata.gz: ae0a2b19435f162c23f7ec9886fdb46d60800a1d246b5df151815c9143e0d7f5cacea4aab6e775b7fdb2119e0f37a5ffe54c569cec1b12d7316b3ba1e3f54432
7
- data.tar.gz: d89c1678a758395746ef7be10642909e3fec5daf07ae68093411c065ad442a9ebfe239fb6054ed94d88467e52a8024618142e9c3bf4f23774c2fc47f7cc1e200
6
+ metadata.gz: da07217f96dbdf528f4b56fb4bb9aad116f2f44172b05290f158a341bde148161911cf431546379eed5e4ad7c4731289d379e1af8e3c07c6e18c302061d53dff
7
+ data.tar.gz: 9ddba0bc1b0128b14e308050469919e5aedb534a47498e71f29a05e975ec3851cb648694d76b8d1cea85f155d74db1a017e6c251d12a20b83fb64b83cc570b6e
data/README.md CHANGED
@@ -170,6 +170,30 @@ months. Currently we support a small number of assertions:
170
170
  * should.change([expression]) { }
171
171
  * should.satisfy { |object| }
172
172
 
173
+ ### Change
174
+
175
+ You can check for changes in an expression.
176
+
177
+ lambda do
178
+ Person.create
179
+ end.should.change('Person.count')
180
+
181
+ Or check for specific changes.
182
+
183
+ lambda do
184
+ Person.create
185
+ Person.create
186
+ end.should.change('Person.count', +2)
187
+
188
+ Or check for multiple changes.
189
+
190
+ lambda do
191
+ Library.bootstrap
192
+ end.should.change(
193
+ 'Shelf.count', +12,
194
+ 'Book.count', +243
195
+ )
196
+
173
197
  If you want to learn more you're probably best of reading the code
174
198
  documentation.
175
199
 
@@ -3,8 +3,8 @@
3
3
  require 'thread'
4
4
 
5
5
  class Peck
6
- VERSION = "0.5.3"
7
-
6
+ VERSION = "0.5.4"
7
+
8
8
  class << self
9
9
  # Returns all the defined contexts.
10
10
  attr_reader :contexts
@@ -15,6 +15,9 @@ class Peck
15
15
  end
16
16
  end
17
17
 
18
+ # A Specification is a proxy object which eventually generates
19
+ # a specification on the context. This is used by the should
20
+ # method in the context class.
18
21
  class Specification < Proxy
19
22
  def not
20
23
  @negated = !@negated
@@ -63,28 +66,39 @@ class Peck
63
66
  result
64
67
  end
65
68
 
66
- def change(expression, change=nil)
67
- if @negated
68
- description = "#{expression} changed"
69
- description << " by #{actual}" if change
70
- else
71
- description = "#{expression} didn't change"
72
- description << " by #{change}" if change
69
+ def change(*expected)
70
+ block_binding = @this.send(:binding)
71
+
72
+ before = expected.in_groups_of(2).map do |expression, _|
73
+ eval(expression, block_binding)
73
74
  end
74
75
 
75
- satisfy(description) do |x|
76
- binding = x.send(:binding)
76
+ block_result = @this.call
77
77
 
78
- before = eval(expression, binding)
79
- result = @this.call
80
- after = eval(expression, binding)
78
+ expected.in_groups_of(2).each_with_index do |(expression, change), index|
79
+ after = eval(expression, block_binding)
80
+ actual = after - before[index]
81
81
 
82
- if difference = change
83
- after == before + difference
82
+ if @negated
83
+ description = "#{expression} changed"
84
+ description << " by expected #{change}" if change
85
+ description << ", actual change: #{actual}"
84
86
  else
85
- before != after
87
+ description = "#{expression} didn't change"
88
+ description << " by expected #{change}" if change
89
+ description << ", actual change: #{actual}"
90
+ end
91
+
92
+ satisfy(description) do |x|
93
+ if change
94
+ after == (before[index] + change)
95
+ else
96
+ before[index] != after
97
+ end
86
98
  end
87
99
  end
100
+
101
+ block_result
88
102
  end
89
103
 
90
104
  def raise(exception_class=nil)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manfred Stienstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-20 00:00:00.000000000 Z
11
+ date: 2015-11-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Concurrent spec framework.
@@ -19,6 +19,10 @@ extensions: []
19
19
  extra_rdoc_files:
20
20
  - COPYING
21
21
  files:
22
+ - COPYING
23
+ - README.md
24
+ - bin/peck
25
+ - lib/peck.rb
22
26
  - lib/peck/context.rb
23
27
  - lib/peck/counter.rb
24
28
  - lib/peck/debug.rb
@@ -33,31 +37,27 @@ files:
33
37
  - lib/peck/notifiers/documentation.rb
34
38
  - lib/peck/option_parser.rb
35
39
  - lib/peck/specification.rb
36
- - lib/peck.rb
37
- - COPYING
38
- - README.md
39
- - bin/peck
40
40
  homepage:
41
41
  licenses: []
42
42
  metadata: {}
43
43
  post_install_message:
44
44
  rdoc_options:
45
- - --charset=utf-8
45
+ - "--charset=utf-8"
46
46
  require_paths:
47
47
  - lib
48
48
  required_ruby_version: !ruby/object:Gem::Requirement
49
49
  requirements:
50
- - - '>='
50
+ - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
53
  required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  requirements:
55
- - - '>='
55
+ - - ">="
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  requirements: []
59
59
  rubyforge_project:
60
- rubygems_version: 2.0.3
60
+ rubygems_version: 2.4.5.1
61
61
  signing_key:
62
62
  specification_version: 4
63
63
  summary: Peck is a concurrent spec framework which inherits a lot from the fabulous