rspec_candy 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTY0ZjE2OGRiYjE4ZTBiMWFhMDk3NmYwOWMzYTMwMzk3OTZmYTc4ZQ==
4
+ NjQyZGUwYzIwZmNlMzJlZmY2NzA5ZDY1MDdiY2QzOWY0M2I3OWNkYQ==
5
5
  data.tar.gz: !binary |-
6
- MTkzMDdiYzhmZWJlNTIwOWE1MjE1YjgwMDRkZDlkMWRmZDZkNGMyMQ==
6
+ ZGY5ZWE3OTFlNTBhNTZkNmI5OGUyYTUwYjg5Y2FlMDJkOGE0MGY5NQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDVjNWJhYzQ0YzUyY2MxOWE5OTliYjNmNjIxMzJkMmY5NTRjM2I5NTY5ODA0
10
- ZDE1ZDE0MWFiNTI4Yjc0YTE3M2E5NDRjYzllMDljZjIyMzFiYTkwM2I2NThj
11
- YWY0ZjQ3N2NkM2NmMjIzMWZjMTVkZGNlODM4MjFlMDY0ZWM2N2E=
9
+ NDRmMGNmMGY5ODEwZDI5YzY5OTc2YWUzYjY2NmM2MGRlYjkzNWZlYTNkNWRi
10
+ NDVmMjlhZGNmYzNjMjRjNDZkYzg2ZWY3MzE0ODc5YjJlZDhjNmRjOWM3M2Zl
11
+ OWI3YmRmY2Y3N2U4NTA5YzJlNTkzZWEzNGQzMjVjMTgzYjAxYWI=
12
12
  data.tar.gz: !binary |-
13
- YTU5ZDk2YmNlMTEzZWNkMjI0MDY5N2Y3YjJiOWQwMzc4MjkwNTE3ZWIzN2Nk
14
- MTkwMjM4ZmY3MDcwM2UzN2I2ZDg4NjMyYWM0OTJhMzdiYjlkOWQ0ZWIzYjA3
15
- NGRhZThmMDZiYmNiMDM4NDg2YjI4MDI4M2M3OGMzNWRlZDg4ODY=
13
+ YWI4N2E1OWM4ZTI4ZWM1ZGRkZDViYzRiMzdlOGQ5OTM3YzM1NzM0ZTg1NzM0
14
+ NGIzNWE2M2QwODM4ZGU3NjhhOGU0Y2Y0ODFmODMxOTlhZTZkOTNkMTIzMWNm
15
+ ZjVhNmIxOWExNTM3NDY1YjhmMDQ2ZmVhYzFhNTU1ODhhYTg3ZWY=
data/README.md CHANGED
@@ -10,28 +10,33 @@ Tested on:
10
10
  - RSpec 3 / Rails 4.2
11
11
 
12
12
 
13
- ##Installation
13
+ ## Installation
14
14
 
15
15
  Add `rspec_candy` to your Gemfile.
16
16
 
17
17
  Now, in your `spec_helper.rb`, add this after your RSpec requires:
18
18
 
19
- require 'rspec_candy/all'
19
+ ```ruby
20
+ require 'rspec_candy/all'
21
+ ```
20
22
 
21
23
  If you only care about the matchers or helpers you can also more specifically require:
22
24
 
23
- require 'rspec_candy/matchers'
24
- require 'rspec_candy/helpers'
25
+ ```ruby
26
+ require 'rspec_candy/matchers'
27
+ require 'rspec_candy/helpers'
28
+ ```
25
29
 
26
-
27
- ##Matchers provided
30
+ ## Matchers provided
28
31
 
29
32
  **be_same_number_as**
30
33
 
31
34
  Tests if the given number is the "same" as the receiving number, regardless of whether you're comparing `Fixnums` (integers), `Floats` and `BigDecimals`:
32
35
 
33
- 100.should be_same_number_as(100.0)
34
- 50.4.should be_same_number_as(BigDecimal('50.4'))
36
+ ```ruby
37
+ 100.should be_same_number_as(100.0)
38
+ 50.4.should be_same_number_as(BigDecimal('50.4'))
39
+ ```
35
40
 
36
41
  Note that "same" means "same for your purposes". Internally the matcher compares normalized results of `#to_s`.
37
42
 
@@ -39,7 +44,9 @@ If you only care about the matchers or helpers you can also more specifically re
39
44
 
40
45
  Tests if the given `Time` or `DateTime` is the same as the receiving `Time` or `DateTime`, [ignoring sub-second differences](https://makandracards.com/makandra/1057-why-two-ruby-time-objects-are-not-equal-although-they-appear-to-be):
41
46
 
42
- Time.parse('2012-12-01 14:00:00.5').should == Time.parse('2012-12-01 14:00')
47
+ ```ruby
48
+ Time.parse('2012-12-01 14:00:00.5').should == Time.parse('2012-12-01 14:00')
49
+ ```
43
50
 
44
51
  Note that two times in a different time zones will still be considered different.
45
52
 
@@ -47,12 +54,13 @@ If you only care about the matchers or helpers you can also more specifically re
47
54
 
48
55
  Matches if the given hash is included in the receiving hash:
49
56
 
50
- { :foo => 'a', :bar => 'b' }.should include_hash(:foo => 'a') # passes
51
- { :foo => 'a', :bar => 'b' }.should include_hash(:foo => 'b') # fails
52
- { :foo => 'a', :bar => 'b' }.should include_hash(:foo => 'a', :baz => 'c') # fails
53
-
57
+ ```ruby
58
+ { :foo => 'a', :bar => 'b' }.should include_hash(:foo => 'a') # passes
59
+ { :foo => 'a', :bar => 'b' }.should include_hash(:foo => 'b') # fails
60
+ { :foo => 'a', :bar => 'b' }.should include_hash(:foo => 'a', :baz => 'c') # fails
61
+ ```
54
62
 
55
- ##Helpers provided
63
+ ## Helpers provided
56
64
 
57
65
 
58
66
  ### Extensions to **Object**
@@ -65,25 +73,28 @@ If you only care about the matchers or helpers you can also more specifically re
65
73
  **should_receive_and_return**
66
74
 
67
75
  Expects multiple returns at once:
68
-
69
- dog.should_receive_and_return(:bark => "Woof", :fetch => "stick")
70
76
 
77
+ ```ruby
78
+ dog.should_receive_and_return(:bark => "Woof", :fetch => "stick")
79
+ ```
71
80
 
72
81
  **should_receive_chain**
73
82
 
74
83
  Expect a chain of method calls:
75
84
 
76
- dog.should_receive_chain(:bark, :upcase).and_return("WOOF")
77
-
85
+ ```ruby
86
+ dog.should_receive_chain(:bark, :upcase).and_return("WOOF")
87
+ ```
78
88
 
79
89
  You can also expect arguments, like:
80
-
81
- dog.should_receive_chain([:bark, 'loudly'], :upcase).and_return("WOOF!!!")
82
-
90
+
91
+ ```ruby
92
+ dog.should_receive_chain([:bark, 'loudly'], :upcase).and_return("WOOF!!!")
93
+ ```
83
94
 
84
95
  **stub_existing**
85
96
 
86
- Like stub, put complains if the method did not exist in the first place.
97
+ Like stub, but complains if the method did not exist in the first place.
87
98
 
88
99
 
89
100
  ### Extensions to **Class**
@@ -92,18 +103,21 @@ If you only care about the matchers or helpers you can also more specifically re
92
103
 
93
104
  Like dup for classes. This will temporarily add a method to a class:
94
105
 
95
- copy = Model.disposable_copy do
96
- def foo; end
97
- end
98
-
99
- object = copy.new
106
+ ```ruby
107
+ copy = Model.disposable_copy do
108
+ def foo; end
109
+ end
100
110
 
111
+ object = copy.new
112
+ ```
101
113
 
102
114
  **new_with_stubs**
103
115
 
104
116
  Instantiates and stubs in one call:
105
117
 
106
- Model.new_with_stubs(:to_param => '1')
118
+ ```ruby
119
+ Model.new_with_stubs(:to_param => '1')
120
+ ```
107
121
 
108
122
  **stub_any_instance**
109
123
 
@@ -118,43 +132,26 @@ If you only care about the matchers or helpers you can also more specifically re
118
132
 
119
133
  Allows parametrizing shared examples, exposes parameters as lets:
120
134
 
121
- shared_examples_for "an animal" do
122
- it 'should make noises' do
123
- subject.say.should == expected_noise
124
- end
125
- end
126
-
127
- describe Dog do
128
- it_should_act_like 'an animal', :expected_noise => 'Woof!'
129
- end
135
+ ```ruby
136
+ shared_examples_for "an animal" do
137
+ it 'should make noises' do
138
+ subject.say.should == expected_noise
139
+ end
140
+ end
130
141
 
142
+ describe Dog do
143
+ it_should_act_like 'an animal', :expected_noise => 'Woof!'
144
+ end
145
+ ```
131
146
 
132
147
  Blocks are passed as a let named "block".
133
148
 
134
149
 
135
- **it_should_run_callbacks**
136
-
137
- Only on Rails.
138
-
139
- Check if callbacks are run. Note the name of the describe block is significant:
140
-
141
- describe Model, '#after_save' do
142
- it_should_run_callbacks :notify_this, :notify_that
143
- end
144
-
145
-
146
-
147
- **it_should_run_callbacks_in_order**
148
-
149
- Like `it_should_run_callbacks`, but also checks the correct order.
150
-
151
-
152
-
153
150
 
154
151
  ### Extensions to **ActiveRecord::Base**
155
152
 
156
153
  **store_with_values**
157
-
154
+
158
155
  Only on Rails.
159
156
 
160
157
  Creates a record without validations or callbacks (like a stub in the database). Can be significantly faster than a factory.
@@ -168,5 +165,3 @@ If you only care about the matchers or helpers you can also more specifically re
168
165
  - `keep_invalid!` has been renamed to `prevent_storage`
169
166
  - `Object#should_not_receive_and_execute` has been removed (same as `Object#should_not_receive`)
170
167
  - `should_receive_all_with` (over-generic method name for a helper that is rarely useful)
171
-
172
-
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- rspec_candy (0.4.1)
4
+ rspec_candy (0.5.0)
5
5
  rspec
6
6
  sneaky-save
7
7
 
@@ -28,3 +28,6 @@ DEPENDENCIES
28
28
  rspec (~> 1.3.2)
29
29
  rspec_candy!
30
30
  sqlite3
31
+
32
+ BUNDLED WITH
33
+ 1.12.5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- rspec_candy (0.4.1)
4
+ rspec_candy (0.5.0)
5
5
  rspec
6
6
  sneaky-save
7
7
 
@@ -49,3 +49,6 @@ DEPENDENCIES
49
49
  rspec (~> 2.14.1)
50
50
  rspec_candy!
51
51
  sqlite3
52
+
53
+ BUNDLED WITH
54
+ 1.12.5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- rspec_candy (0.4.1)
4
+ rspec_candy (0.5.0)
5
5
  rspec
6
6
  sneaky-save
7
7
 
@@ -59,3 +59,6 @@ DEPENDENCIES
59
59
  rspec (~> 3.2.0)
60
60
  rspec_candy!
61
61
  sqlite3
62
+
63
+ BUNDLED WITH
64
+ 1.12.5
@@ -10,6 +10,5 @@ require 'rspec_candy/helpers/stub_existing'
10
10
 
11
11
  if RSpecCandy::Switcher.active_record_loaded?
12
12
  require 'rspec_candy/helpers/rails/store_with_values'
13
- require 'rspec_candy/helpers/rails/it_should_run_callbacks'
14
13
  require 'rspec_candy/helpers/rails/prevent_storage'
15
14
  end
@@ -1,3 +1,3 @@
1
1
  module RSpecCandy
2
- VERSION = '0.4.1'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_candy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-18 00:00:00.000000000 Z
12
+ date: 2018-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -64,7 +64,6 @@ files:
64
64
  - lib/rspec_candy/helpers/disposable_copy.rb
65
65
  - lib/rspec_candy/helpers/it_should_act_like.rb
66
66
  - lib/rspec_candy/helpers/new_with_stubs.rb
67
- - lib/rspec_candy/helpers/rails/it_should_run_callbacks.rb
68
67
  - lib/rspec_candy/helpers/rails/prevent_storage.rb
69
68
  - lib/rspec_candy/helpers/rails/store_with_values.rb
70
69
  - lib/rspec_candy/helpers/should_receive_and_execute.rb
@@ -82,7 +81,6 @@ files:
82
81
  - spec/rspec_candy/helpers/disposable_copy_spec.rb
83
82
  - spec/rspec_candy/helpers/it_should_act_like_spec.rb
84
83
  - spec/rspec_candy/helpers/new_with_stubs_spec.rb
85
- - spec/rspec_candy/helpers/rails/it_should_run_callbacks_spec.rb
86
84
  - spec/rspec_candy/helpers/rails/prevent_storage_spec.rb
87
85
  - spec/rspec_candy/helpers/rails/store_with_values_spec.rb
88
86
  - spec/rspec_candy/helpers/should_receive_and_execute_spec.rb
@@ -120,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
118
  version: '0'
121
119
  requirements: []
122
120
  rubyforge_project:
123
- rubygems_version: 2.4.3
121
+ rubygems_version: 2.6.13
124
122
  signing_key:
125
123
  specification_version: 4
126
124
  summary: RSpec helpers and matchers we use in our daily work at makandra.
@@ -1,92 +0,0 @@
1
- module RSpecCandy
2
- module Helpers
3
- module Rails
4
- module ItShouldRunCallbacks
5
-
6
- module ExampleGroupMethods
7
- def self.included(by)
8
- by.class_eval do
9
-
10
- def it_should_run_callbacks_in_order(*callbacks)
11
- callbacks.push(:ordered => true)
12
- it_should_run_callbacks(*callbacks)
13
- end
14
-
15
- def it_should_run_callbacks(*callbacks)
16
- options = callbacks.last.is_a?(Hash) ? callbacks.pop : {}
17
- reason = callbacks.pop if callbacks.last.is_a?(String)
18
- should = ['should run callbacks', callbacks.inspect, ('in order' if options[:ordered]), reason].compact.join ' '
19
-
20
- prose = case Switcher.rspec_version
21
- when 1
22
- description_parts.last
23
- else
24
- description.split(/(?=#)/).last
25
- end
26
-
27
- send(:it, should) do
28
- extend ExampleMethods
29
- callbacks.each do |callback|
30
- expectation = subject.should_receive(callback).once
31
- expectation.ordered if options[:ordered]
32
- end
33
- run_all_callbacks(prose)
34
- end
35
- end
36
- end
37
- end
38
- end
39
-
40
- module ExampleMethods
41
- private
42
-
43
- def run_all_callbacks(prose)
44
- run_active_record_callbacks_from_prose(prose)
45
- end
46
-
47
- case Switcher.rspec_version
48
- when 1
49
-
50
- def run_active_record_callbacks_from_prose(prose)
51
- subject.run_callbacks(prose.sub(/^#/, ''))
52
- end
53
-
54
- else
55
-
56
- def run_active_record_callbacks_from_prose(prose)
57
- hook = prose.split.last.sub(/^#/, '')
58
- if hook.sub!(/_on_(create|update)$/, '')
59
- condition = "validation_context == :#{$1}"
60
- else
61
- condition = nil
62
- end
63
- if hook == 'validate'
64
- kind = 'before'
65
- action = 'validate'
66
- else
67
- hook =~ /^(before|after|around)_(.*)$/
68
- kind = $1
69
- action = $2
70
- end
71
- # Run all matching callbacks
72
- subject.send("_#{action}_callbacks").send(kind == 'after' ? :reverse_each : :each) do |callback|
73
- if callback.kind.to_s == kind && (condition.nil? || callback.options[:if].include?(condition))
74
- subject.send(callback.filter.to_s.gsub(/[\(,\)]/, '').to_sym) {}
75
- end
76
- end
77
- end
78
-
79
- end
80
- end
81
-
82
- case Switcher.rspec_version
83
- when 1
84
- Spec::Example::ExampleGroupMethods.send(:include, self::ExampleGroupMethods)
85
- else
86
- RSpec::Core::ExampleGroup.singleton_class.send(:include, self::ExampleGroupMethods)
87
- end
88
-
89
- end
90
- end
91
- end
92
- end
@@ -1,84 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RSpecCandy::Helpers::Rails::ItShouldRunCallbacks do
4
-
5
- describe '#it_should_run_callbacks' do
6
-
7
- it 'should pass if all callbacks have been run' do
8
- <<-describe_block.should pass_as_describe_block
9
- describe Model, '#after_save' do
10
- it_should_run_callbacks :after_save_callback2, :after_save_callback1
11
- end
12
- describe_block
13
- end
14
-
15
- it 'should only attempt to run the proper callbacks have been run' do
16
- <<-describe_block.should fail_as_describe_block
17
- describe Model, '#before_save' do
18
- it_should_run_callbacks :after_save_callback2, :after_save_callback1
19
- end
20
- describe_block
21
- end
22
-
23
- it 'should not pass if a callback has not been run' do
24
- <<-describe_block.should fail_as_describe_block
25
- describe Model, '#after_create' do
26
- it_should_run_callbacks :after_create_callback, :unknown_callback
27
- end
28
- describe_block
29
- end
30
-
31
- it 'should not actually execute the callbacks' do
32
- <<-describe_block.should pass_as_describe_block
33
- def Model.after_save_callback2
34
- raise "called!"
35
- end
36
-
37
- describe Model, '#after_save' do
38
- it_should_run_callbacks :after_save_callback1
39
- end
40
- describe_block
41
- end
42
-
43
- end
44
-
45
- describe '#it_should_run_callbacks_in_order' do
46
-
47
- supported_callbacks = case RSpecCandy::Switcher.rspec_version
48
- when 1
49
- %w[before after]
50
- else
51
- %w[before after around]
52
- end
53
-
54
- supported_callbacks.each do |kind|
55
-
56
- it "should pass if all #{kind} callbacks are run in order" do
57
- <<-describe_block.should pass_as_describe_block
58
- describe Model, '##{kind}_save' do
59
- it_should_run_callbacks_in_order :#{kind}_save_callback1, :#{kind}_save_callback2
60
- end
61
- describe_block
62
- end
63
-
64
- it "should not pass if a #{kind} callback has not been run" do
65
- <<-describe_block.should fail_as_describe_block
66
- describe Model, '##{kind}_create' do
67
- it_should_run_callbacks_in_order :#{kind}_create_callback, :unknown_callback
68
- end
69
- describe_block
70
- end
71
-
72
- it "should not pass if #{kind} callbacks are run out of order" do
73
- <<-describe_block.should fail_as_describe_block
74
- describe Model, '##{kind}_save' do
75
- it_should_run_callbacks_in_order :#{kind}_save_callback2, :#{kind}_save_callback1
76
- end
77
- describe_block
78
- end
79
-
80
- end
81
-
82
- end
83
-
84
- end