warp 1.2.3 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.travis.yml +0 -1
- data/CHANGELOG.md +6 -0
- data/Gemfile +4 -1
- data/README.md +10 -0
- data/gemfiles/rails_3.2_rspec_2.14.gemfile +3 -1
- data/gemfiles/rails_3.2_rspec_2.99.gemfile +3 -1
- data/gemfiles/rails_3.2_rspec_3.1.gemfile +3 -1
- data/gemfiles/rails_4.0_rspec_2.14.gemfile +3 -1
- data/gemfiles/rails_4.0_rspec_2.99.gemfile +3 -1
- data/gemfiles/rails_4.0_rspec_3.1.gemfile +3 -1
- data/gemfiles/rails_4.1_rspec_2.14.gemfile +3 -1
- data/gemfiles/rails_4.1_rspec_2.99.gemfile +3 -1
- data/gemfiles/rails_4.1_rspec_3.1.gemfile +3 -1
- data/gemfiles/rails_4.2.rc1_rspec_2.14.gemfile +3 -1
- data/gemfiles/rails_4.2.rc1_rspec_2.99.gemfile +3 -1
- data/gemfiles/rails_4.2.rc1_rspec_3.1.gemfile +3 -1
- data/lib/warp/action_matchers/create_matcher.rb +48 -0
- data/lib/warp/action_matchers/matcher.rb +11 -0
- data/lib/warp/action_matchers.rb +9 -0
- data/lib/warp/controller_matchers/assign_matcher.rb +2 -0
- data/lib/warp/controller_matchers/set_flash_matcher.rb +2 -0
- data/lib/warp/controller_matchers.rb +1 -1
- data/lib/warp/instrument.rb +81 -0
- data/lib/warp/matcher.rb +2 -0
- data/lib/warp/model_matchers/association_matcher.rb +2 -0
- data/lib/warp/model_matchers/attribute_matcher.rb +3 -1
- data/lib/warp/model_matchers/matcher.rb +2 -0
- data/lib/warp/model_matchers/validation_matcher.rb +2 -0
- data/lib/warp/model_matchers.rb +1 -3
- data/lib/warp/version.rb +2 -2
- data/lib/warp.rb +1 -4
- data/spec/spec_helper.rb +4 -1
- data/spec/support/model_helpers.rb +3 -1
- data/spec/warp/action_matchers/create_matcher_spec.rb +39 -0
- data/spec/warp/controller_matchers/assign_matcher_spec.rb +1 -1
- data/spec/warp/controller_matchers/set_flash_matcher_spec.rb +1 -1
- data/spec/warp/instrument_spec.rb +50 -0
- data/spec/warp/model_helpers/association_matcher_spec.rb +1 -1
- data/spec/warp/model_helpers/attribute_matcher_spec.rb +1 -1
- data/spec/warp/model_helpers/validation_matcher_spec.rb +1 -1
- metadata +19 -11
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NDliNWY1MmRlZmM1NjRlMDJhMzYwNWYxMTQ5NjAzNjY3MTM1NzBhYg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YTMzNzFhMGE3YTcwYzRhNDcwY2Q1ZThmODE1NzFlOGQ2YjNjMDVmYQ==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZjgxODljNmI3MmY0MTZiYzViM2M5OWI3ZjY5NTkwM2JlYTY3YTY5MWVkZjg1
|
10
|
+
M2Y5ZGRkN2M5N2I0Nzg5ZTAwNjJlZjg4YjAxNjAwY2ZiYTZjMDk2MWQ5ZmE0
|
11
|
+
NDAwOTdiYjlkNDYyMWU4MjBlM2NhYzZiNDU3NmVhNTRlMmVmMjM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDI5NGY0NGNmMWU2MmExMTE5MmUwZjYyZTFmYTUxMDkwYmFlMGM4NWI1OTMx
|
14
|
+
OWIzZjkwMjNkMjgzMWFhZTI5NmFhZDUxNWJlMzQ3OTEzNDk1NTUzOTJjNDk1
|
15
|
+
ZjFhN2RkOWVjNmE0ZWJlODY1MGQ4NmIzYjc1MGYxZWFhZDkyM2M=
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -11,8 +11,11 @@ gem "fuubar"
|
|
11
11
|
gem "simplecov", require: false
|
12
12
|
gem "coveralls", require: false
|
13
13
|
|
14
|
+
gem "activerecord-nulldb-adapter", require: false
|
15
|
+
|
14
16
|
group :tools do
|
15
17
|
gem "guard"
|
16
18
|
gem "guard-rspec"
|
17
|
-
gem "byebug"
|
19
|
+
gem "byebug", platform: [:ruby_20, :ruby_21]
|
20
|
+
gem "debugger", platform: :ruby_19
|
18
21
|
end
|
data/README.md
CHANGED
@@ -218,6 +218,16 @@ Ensures that a `validates_uniqueness_of` validator is present on the attribute.
|
|
218
218
|
specify { expect(user).to validate_uniqueness_of(:email, scope: :company) }
|
219
219
|
```
|
220
220
|
|
221
|
+
### Creation Matchers
|
222
|
+
|
223
|
+
#### creates
|
224
|
+
|
225
|
+
Ensures that a record is created.
|
226
|
+
|
227
|
+
```ruby
|
228
|
+
specify { expect{post :create, params}.to create(Post) }
|
229
|
+
```
|
230
|
+
|
221
231
|
## Contributing
|
222
232
|
|
223
233
|
1. Fork it
|
@@ -8,6 +8,7 @@ gem "rake"
|
|
8
8
|
gem "fuubar"
|
9
9
|
gem "simplecov", :require => false
|
10
10
|
gem "coveralls", :require => false
|
11
|
+
gem "activerecord-nulldb-adapter", :require => false
|
11
12
|
gem "activesupport", "~> 3.2", :require => "active_support/all"
|
12
13
|
gem "actionpack", "~> 3.2", :require => "action_controller"
|
13
14
|
gem "activerecord", "~> 3.2", :require => "active_record"
|
@@ -16,7 +17,8 @@ gem "rspec", "~> 2.14"
|
|
16
17
|
group :tools do
|
17
18
|
gem "guard"
|
18
19
|
gem "guard-rspec"
|
19
|
-
gem "byebug"
|
20
|
+
gem "byebug", :platform => [:ruby_20, :ruby_21]
|
21
|
+
gem "debugger", :platform => :ruby_19
|
20
22
|
end
|
21
23
|
|
22
24
|
gemspec :path => "../"
|
@@ -8,6 +8,7 @@ gem "rake"
|
|
8
8
|
gem "fuubar"
|
9
9
|
gem "simplecov", :require => false
|
10
10
|
gem "coveralls", :require => false
|
11
|
+
gem "activerecord-nulldb-adapter", :require => false
|
11
12
|
gem "activesupport", "~> 3.2", :require => "active_support/all"
|
12
13
|
gem "actionpack", "~> 3.2", :require => "action_controller"
|
13
14
|
gem "activerecord", "~> 3.2", :require => "active_record"
|
@@ -16,7 +17,8 @@ gem "rspec", "~> 2.99"
|
|
16
17
|
group :tools do
|
17
18
|
gem "guard"
|
18
19
|
gem "guard-rspec"
|
19
|
-
gem "byebug"
|
20
|
+
gem "byebug", :platform => [:ruby_20, :ruby_21]
|
21
|
+
gem "debugger", :platform => :ruby_19
|
20
22
|
end
|
21
23
|
|
22
24
|
gemspec :path => "../"
|
@@ -8,6 +8,7 @@ gem "rake"
|
|
8
8
|
gem "fuubar"
|
9
9
|
gem "simplecov", :require => false
|
10
10
|
gem "coveralls", :require => false
|
11
|
+
gem "activerecord-nulldb-adapter", :require => false
|
11
12
|
gem "activesupport", "~> 3.2", :require => "active_support/all"
|
12
13
|
gem "actionpack", "~> 3.2", :require => "action_controller"
|
13
14
|
gem "activerecord", "~> 3.2", :require => "active_record"
|
@@ -16,7 +17,8 @@ gem "rspec", "~> 3.1"
|
|
16
17
|
group :tools do
|
17
18
|
gem "guard"
|
18
19
|
gem "guard-rspec"
|
19
|
-
gem "byebug"
|
20
|
+
gem "byebug", :platform => [:ruby_20, :ruby_21]
|
21
|
+
gem "debugger", :platform => :ruby_19
|
20
22
|
end
|
21
23
|
|
22
24
|
gemspec :path => "../"
|
@@ -8,6 +8,7 @@ gem "rake"
|
|
8
8
|
gem "fuubar"
|
9
9
|
gem "simplecov", :require => false
|
10
10
|
gem "coveralls", :require => false
|
11
|
+
gem "activerecord-nulldb-adapter", :require => false
|
11
12
|
gem "activesupport", "~> 4.0", :require => "active_support/all"
|
12
13
|
gem "actionpack", "~> 4.0", :require => "action_controller"
|
13
14
|
gem "activerecord", "~> 4.0", :require => "active_record"
|
@@ -16,7 +17,8 @@ gem "rspec", "~> 2.14"
|
|
16
17
|
group :tools do
|
17
18
|
gem "guard"
|
18
19
|
gem "guard-rspec"
|
19
|
-
gem "byebug"
|
20
|
+
gem "byebug", :platform => [:ruby_20, :ruby_21]
|
21
|
+
gem "debugger", :platform => :ruby_19
|
20
22
|
end
|
21
23
|
|
22
24
|
gemspec :path => "../"
|
@@ -8,6 +8,7 @@ gem "rake"
|
|
8
8
|
gem "fuubar"
|
9
9
|
gem "simplecov", :require => false
|
10
10
|
gem "coveralls", :require => false
|
11
|
+
gem "activerecord-nulldb-adapter", :require => false
|
11
12
|
gem "activesupport", "~> 4.0", :require => "active_support/all"
|
12
13
|
gem "actionpack", "~> 4.0", :require => "action_controller"
|
13
14
|
gem "activerecord", "~> 4.0", :require => "active_record"
|
@@ -16,7 +17,8 @@ gem "rspec", "~> 2.99"
|
|
16
17
|
group :tools do
|
17
18
|
gem "guard"
|
18
19
|
gem "guard-rspec"
|
19
|
-
gem "byebug"
|
20
|
+
gem "byebug", :platform => [:ruby_20, :ruby_21]
|
21
|
+
gem "debugger", :platform => :ruby_19
|
20
22
|
end
|
21
23
|
|
22
24
|
gemspec :path => "../"
|
@@ -8,6 +8,7 @@ gem "rake"
|
|
8
8
|
gem "fuubar"
|
9
9
|
gem "simplecov", :require => false
|
10
10
|
gem "coveralls", :require => false
|
11
|
+
gem "activerecord-nulldb-adapter", :require => false
|
11
12
|
gem "activesupport", "~> 4.0", :require => "active_support/all"
|
12
13
|
gem "actionpack", "~> 4.0", :require => "action_controller"
|
13
14
|
gem "activerecord", "~> 4.0", :require => "active_record"
|
@@ -16,7 +17,8 @@ gem "rspec", "~> 3.1"
|
|
16
17
|
group :tools do
|
17
18
|
gem "guard"
|
18
19
|
gem "guard-rspec"
|
19
|
-
gem "byebug"
|
20
|
+
gem "byebug", :platform => [:ruby_20, :ruby_21]
|
21
|
+
gem "debugger", :platform => :ruby_19
|
20
22
|
end
|
21
23
|
|
22
24
|
gemspec :path => "../"
|
@@ -8,6 +8,7 @@ gem "rake"
|
|
8
8
|
gem "fuubar"
|
9
9
|
gem "simplecov", :require => false
|
10
10
|
gem "coveralls", :require => false
|
11
|
+
gem "activerecord-nulldb-adapter", :require => false
|
11
12
|
gem "activesupport", "~> 4.1", :require => "active_support/all"
|
12
13
|
gem "actionpack", "~> 4.1", :require => "action_controller"
|
13
14
|
gem "activerecord", "~> 4.1", :require => "active_record"
|
@@ -17,7 +18,8 @@ gem "rspec", "~> 2.14"
|
|
17
18
|
group :tools do
|
18
19
|
gem "guard"
|
19
20
|
gem "guard-rspec"
|
20
|
-
gem "byebug"
|
21
|
+
gem "byebug", :platform => [:ruby_20, :ruby_21]
|
22
|
+
gem "debugger", :platform => :ruby_19
|
21
23
|
end
|
22
24
|
|
23
25
|
gemspec :path => "../"
|
@@ -8,6 +8,7 @@ gem "rake"
|
|
8
8
|
gem "fuubar"
|
9
9
|
gem "simplecov", :require => false
|
10
10
|
gem "coveralls", :require => false
|
11
|
+
gem "activerecord-nulldb-adapter", :require => false
|
11
12
|
gem "activesupport", "~> 4.1", :require => "active_support/all"
|
12
13
|
gem "actionpack", "~> 4.1", :require => "action_controller"
|
13
14
|
gem "activerecord", "~> 4.1", :require => "active_record"
|
@@ -17,7 +18,8 @@ gem "rspec", "~> 2.99"
|
|
17
18
|
group :tools do
|
18
19
|
gem "guard"
|
19
20
|
gem "guard-rspec"
|
20
|
-
gem "byebug"
|
21
|
+
gem "byebug", :platform => [:ruby_20, :ruby_21]
|
22
|
+
gem "debugger", :platform => :ruby_19
|
21
23
|
end
|
22
24
|
|
23
25
|
gemspec :path => "../"
|
@@ -8,6 +8,7 @@ gem "rake"
|
|
8
8
|
gem "fuubar"
|
9
9
|
gem "simplecov", :require => false
|
10
10
|
gem "coveralls", :require => false
|
11
|
+
gem "activerecord-nulldb-adapter", :require => false
|
11
12
|
gem "activesupport", "~> 4.1", :require => "active_support/all"
|
12
13
|
gem "actionpack", "~> 4.1", :require => "action_controller"
|
13
14
|
gem "activerecord", "~> 4.1", :require => "active_record"
|
@@ -17,7 +18,8 @@ gem "rspec", "~> 3.1"
|
|
17
18
|
group :tools do
|
18
19
|
gem "guard"
|
19
20
|
gem "guard-rspec"
|
20
|
-
gem "byebug"
|
21
|
+
gem "byebug", :platform => [:ruby_20, :ruby_21]
|
22
|
+
gem "debugger", :platform => :ruby_19
|
21
23
|
end
|
22
24
|
|
23
25
|
gemspec :path => "../"
|
@@ -8,6 +8,7 @@ gem "rake"
|
|
8
8
|
gem "fuubar"
|
9
9
|
gem "simplecov", :require => false
|
10
10
|
gem "coveralls", :require => false
|
11
|
+
gem "activerecord-nulldb-adapter", :require => false
|
11
12
|
gem "activesupport", "~> 4.2.rc1", :require => "active_support/all"
|
12
13
|
gem "actionpack", "~> 4.2.rc1", :require => "action_controller"
|
13
14
|
gem "activerecord", "~> 4.2.rc1", :require => "active_record"
|
@@ -16,7 +17,8 @@ gem "rspec", "~> 2.14"
|
|
16
17
|
group :tools do
|
17
18
|
gem "guard"
|
18
19
|
gem "guard-rspec"
|
19
|
-
gem "byebug"
|
20
|
+
gem "byebug", :platform => [:ruby_20, :ruby_21]
|
21
|
+
gem "debugger", :platform => :ruby_19
|
20
22
|
end
|
21
23
|
|
22
24
|
gemspec :path => "../"
|
@@ -8,6 +8,7 @@ gem "rake"
|
|
8
8
|
gem "fuubar"
|
9
9
|
gem "simplecov", :require => false
|
10
10
|
gem "coveralls", :require => false
|
11
|
+
gem "activerecord-nulldb-adapter", :require => false
|
11
12
|
gem "activesupport", "~> 4.2.rc1", :require => "active_support/all"
|
12
13
|
gem "actionpack", "~> 4.2.rc1", :require => "action_controller"
|
13
14
|
gem "activerecord", "~> 4.2.rc1", :require => "active_record"
|
@@ -16,7 +17,8 @@ gem "rspec", "~> 2.99"
|
|
16
17
|
group :tools do
|
17
18
|
gem "guard"
|
18
19
|
gem "guard-rspec"
|
19
|
-
gem "byebug"
|
20
|
+
gem "byebug", :platform => [:ruby_20, :ruby_21]
|
21
|
+
gem "debugger", :platform => :ruby_19
|
20
22
|
end
|
21
23
|
|
22
24
|
gemspec :path => "../"
|
@@ -8,6 +8,7 @@ gem "rake"
|
|
8
8
|
gem "fuubar"
|
9
9
|
gem "simplecov", :require => false
|
10
10
|
gem "coveralls", :require => false
|
11
|
+
gem "activerecord-nulldb-adapter", :require => false
|
11
12
|
gem "activesupport", "~> 4.2.rc1", :require => "active_support/all"
|
12
13
|
gem "actionpack", "~> 4.2.rc1", :require => "action_controller"
|
13
14
|
gem "activerecord", "~> 4.2.rc1", :require => "active_record"
|
@@ -16,7 +17,8 @@ gem "rspec", "~> 3.1"
|
|
16
17
|
group :tools do
|
17
18
|
gem "guard"
|
18
19
|
gem "guard-rspec"
|
19
|
-
gem "byebug"
|
20
|
+
gem "byebug", :platform => [:ruby_20, :ruby_21]
|
21
|
+
gem "debugger", :platform => :ruby_19
|
20
22
|
end
|
21
23
|
|
22
24
|
gemspec :path => "../"
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "warp/action_matchers/matcher"
|
2
|
+
require "warp/instrument"
|
3
|
+
|
4
|
+
module Warp
|
5
|
+
module ActionMatchers
|
6
|
+
class CreateMatcher < Warp::ActionMatchers::Matcher
|
7
|
+
if ActiveRecord::Base.private_method_defined?(:_create_record)
|
8
|
+
CREATE_METHOD = :_create_record
|
9
|
+
else
|
10
|
+
CREATE_METHOD = :create
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :model
|
14
|
+
|
15
|
+
def initialize(model)
|
16
|
+
@model = model
|
17
|
+
end
|
18
|
+
|
19
|
+
def matches?(actual)
|
20
|
+
unless actual.respond_to?(:call)
|
21
|
+
raise "The create matcher can only match against callables."
|
22
|
+
end
|
23
|
+
|
24
|
+
instrument = Warp::Instrument.for(model, CREATE_METHOD)
|
25
|
+
|
26
|
+
instrument.run { actual.call }
|
27
|
+
|
28
|
+
instrument.calls.size > 0
|
29
|
+
end
|
30
|
+
|
31
|
+
def description
|
32
|
+
"create a #{model.name}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def failure_message
|
36
|
+
"expected a #{model.name} to be created"
|
37
|
+
end
|
38
|
+
|
39
|
+
def failure_message_when_negated
|
40
|
+
"expected no #{model.name} to be created"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def create(model)
|
45
|
+
CreateMatcher.new(model)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Warp
|
2
|
+
class Instrument
|
3
|
+
class << self
|
4
|
+
def for(klass, method)
|
5
|
+
@@registry ||= {}
|
6
|
+
@@registry[klass] ||= {}
|
7
|
+
@@registry[klass][method] || new(klass, method)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def register(instrument)
|
13
|
+
@@registry ||= {}
|
14
|
+
@@registry[instrument.klass] ||= {}
|
15
|
+
@@registry[instrument.klass][instrument.method] = instrument
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_accessor :klass, :method, :hook, :enabled, :calls
|
20
|
+
|
21
|
+
def initialize(klass, method)
|
22
|
+
self.klass = klass
|
23
|
+
self.method = method
|
24
|
+
self.enabled = false
|
25
|
+
self.calls = []
|
26
|
+
setup_hook
|
27
|
+
|
28
|
+
self.class.send(:register, self)
|
29
|
+
end
|
30
|
+
|
31
|
+
def run
|
32
|
+
enable
|
33
|
+
yield
|
34
|
+
disable
|
35
|
+
end
|
36
|
+
|
37
|
+
def enabled?
|
38
|
+
enabled
|
39
|
+
end
|
40
|
+
|
41
|
+
def log(args)
|
42
|
+
calls << args
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def enable
|
48
|
+
self.enabled = true
|
49
|
+
end
|
50
|
+
|
51
|
+
def disable
|
52
|
+
self.enabled = false
|
53
|
+
end
|
54
|
+
|
55
|
+
def setup_hook
|
56
|
+
if Module.method_defined?(:prepend)
|
57
|
+
self.hook = Module.new
|
58
|
+
|
59
|
+
hook.send(:define_method, method) do |*args|
|
60
|
+
if Warp::Instrument.for(self.class, __method__).enabled?
|
61
|
+
Warp::Instrument.for(self.class, __method__).log(args)
|
62
|
+
end
|
63
|
+
|
64
|
+
super(*args)
|
65
|
+
end
|
66
|
+
|
67
|
+
klass.prepend(hook)
|
68
|
+
else
|
69
|
+
original_method = klass.instance_method(method)
|
70
|
+
|
71
|
+
klass.send(:define_method, method) do |*args|
|
72
|
+
if Warp::Instrument.for(self.class, __method__).enabled?
|
73
|
+
Warp::Instrument.for(self.class, __method__).log(args)
|
74
|
+
end
|
75
|
+
|
76
|
+
original_method.bind(self).call(*args)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/warp/matcher.rb
CHANGED
data/lib/warp/model_matchers.rb
CHANGED
@@ -2,8 +2,6 @@ unless defined?(ActiveModel)
|
|
2
2
|
raise RuntimeError, "ActiveModel is required to use Warp::ModelMatchers."
|
3
3
|
end
|
4
4
|
|
5
|
-
require "warp/model_matchers/matcher"
|
6
|
-
|
7
5
|
# require "warp/model_matchers/error_matcher"
|
8
6
|
require "warp/model_matchers/validation_matcher"
|
9
7
|
|
@@ -13,5 +11,5 @@ if defined?(ActiveRecord)
|
|
13
11
|
end
|
14
12
|
|
15
13
|
RSpec.configure do |config|
|
16
|
-
config.include Warp::ModelMatchers
|
14
|
+
config.include Warp::ModelMatchers, type: :model
|
17
15
|
end
|
data/lib/warp/version.rb
CHANGED
data/lib/warp.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -25,7 +25,7 @@ else
|
|
25
25
|
Bundler.require(:default, :tools)
|
26
26
|
end
|
27
27
|
|
28
|
-
if
|
28
|
+
if defined?(Rails) && !Rails.respond_to?(:env)
|
29
29
|
module Rails
|
30
30
|
def self.env
|
31
31
|
"default_env"
|
@@ -33,6 +33,9 @@ if ActionPack.respond_to?(:version) && ActionPack.version.to_s =~ /^4\.2/
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
require "activerecord-nulldb-adapter"
|
37
|
+
ActiveRecord::Base.establish_connection adapter: :nulldb
|
38
|
+
|
36
39
|
Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f }
|
37
40
|
|
38
41
|
RSpec.configure do |config|
|
@@ -2,6 +2,8 @@ module ModelHelpers
|
|
2
2
|
def build_model(&blk)
|
3
3
|
let(:model) do
|
4
4
|
Class.new(ActiveRecord::Base) do
|
5
|
+
attr_accessor :id
|
6
|
+
|
5
7
|
def self.name
|
6
8
|
"TestModel"
|
7
9
|
end
|
@@ -27,7 +29,7 @@ module ModelHelpers
|
|
27
29
|
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
|
28
30
|
end
|
29
31
|
|
30
|
-
instance_eval(&blk)
|
32
|
+
instance_eval(&blk) if blk
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Warp::ActionMatchers::CreateMatcher do
|
4
|
+
build_model
|
5
|
+
|
6
|
+
subject { create(model) }
|
7
|
+
|
8
|
+
context "when created with #create" do
|
9
|
+
let(:block) { -> { model.create({}) } }
|
10
|
+
|
11
|
+
specify { expect(subject).to match block }
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when created with #save" do
|
15
|
+
let(:block) { -> { model.new.save } }
|
16
|
+
|
17
|
+
specify { expect(subject).to match block }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when nothing created" do
|
21
|
+
let(:block) { -> { return } }
|
22
|
+
|
23
|
+
specify { expect(subject).to_not match block }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#desciption" do
|
27
|
+
subject { super().description }
|
28
|
+
|
29
|
+
specify { expect(subject).to eq "create a TestModel" }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe_failure_message do
|
33
|
+
specify { expect(subject).to eq "expected a TestModel to be created" }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe_failure_message_when_negated do
|
37
|
+
specify { expect(subject).to eq "expected no TestModel to be created" }
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Warp::Instrument do
|
4
|
+
let(:klass) { Class.new }
|
5
|
+
let(:method) { :foo }
|
6
|
+
let(:instrument) { Warp::Instrument.for(klass, method) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
klass.send(:define_method, method) {|*_| return nil }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".for" do
|
13
|
+
subject { instrument }
|
14
|
+
|
15
|
+
context "with no existing instrument" do
|
16
|
+
specify { expect(subject).to be_a Warp::Instrument }
|
17
|
+
specify { expect(subject).to_not be_enabled }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "with an existing instrument" do
|
21
|
+
let!(:existing) { subject }
|
22
|
+
|
23
|
+
specify { expect(subject).to equal existing }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#run" do
|
28
|
+
specify { expect{|blk| instrument.run(&blk) }.to yield_control }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#calls" do
|
32
|
+
subject { instrument.calls }
|
33
|
+
|
34
|
+
context "when no calls have been logged" do
|
35
|
+
specify { expect(subject).to eq [] }
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when a call has been logged" do
|
39
|
+
let(:args) { [{baz: :quz}] }
|
40
|
+
|
41
|
+
before do
|
42
|
+
instrument.run do
|
43
|
+
klass.new.send(method, *args)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
specify { expect(subject).to eq [args] }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Drake-Brockman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 2.14.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.14.0
|
27
27
|
description: Warp provides a selection of inteligent RSpec matchers for your model,
|
@@ -32,11 +32,11 @@ executables: []
|
|
32
32
|
extensions: []
|
33
33
|
extra_rdoc_files: []
|
34
34
|
files:
|
35
|
-
-
|
36
|
-
-
|
37
|
-
-
|
38
|
-
-
|
39
|
-
-
|
35
|
+
- .gitignore
|
36
|
+
- .rspec
|
37
|
+
- .ruby-gemset
|
38
|
+
- .ruby-version
|
39
|
+
- .travis.yml
|
40
40
|
- Appraisals
|
41
41
|
- CHANGELOG.md
|
42
42
|
- Gemfile
|
@@ -57,9 +57,13 @@ files:
|
|
57
57
|
- gemfiles/rails_4.2.rc1_rspec_2.99.gemfile
|
58
58
|
- gemfiles/rails_4.2.rc1_rspec_3.1.gemfile
|
59
59
|
- lib/warp.rb
|
60
|
+
- lib/warp/action_matchers.rb
|
61
|
+
- lib/warp/action_matchers/create_matcher.rb
|
62
|
+
- lib/warp/action_matchers/matcher.rb
|
60
63
|
- lib/warp/controller_matchers.rb
|
61
64
|
- lib/warp/controller_matchers/assign_matcher.rb
|
62
65
|
- lib/warp/controller_matchers/set_flash_matcher.rb
|
66
|
+
- lib/warp/instrument.rb
|
63
67
|
- lib/warp/matcher.rb
|
64
68
|
- lib/warp/model_matchers.rb
|
65
69
|
- lib/warp/model_matchers/association_matcher.rb
|
@@ -74,8 +78,10 @@ files:
|
|
74
78
|
- spec/support/match_helpers.rb
|
75
79
|
- spec/support/model_helpers.rb
|
76
80
|
- spec/support/with_contexts_helpers.rb
|
81
|
+
- spec/warp/action_matchers/create_matcher_spec.rb
|
77
82
|
- spec/warp/controller_matchers/assign_matcher_spec.rb
|
78
83
|
- spec/warp/controller_matchers/set_flash_matcher_spec.rb
|
84
|
+
- spec/warp/instrument_spec.rb
|
79
85
|
- spec/warp/model_helpers/association_matcher_spec.rb
|
80
86
|
- spec/warp/model_helpers/attribute_matcher_spec.rb
|
81
87
|
- spec/warp/model_helpers/validation_matcher_spec.rb
|
@@ -90,12 +96,12 @@ require_paths:
|
|
90
96
|
- lib
|
91
97
|
required_ruby_version: !ruby/object:Gem::Requirement
|
92
98
|
requirements:
|
93
|
-
- -
|
99
|
+
- - ! '>='
|
94
100
|
- !ruby/object:Gem::Version
|
95
101
|
version: '0'
|
96
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
103
|
requirements:
|
98
|
-
- -
|
104
|
+
- - ! '>='
|
99
105
|
- !ruby/object:Gem::Version
|
100
106
|
version: '0'
|
101
107
|
requirements: []
|
@@ -111,8 +117,10 @@ test_files:
|
|
111
117
|
- spec/support/match_helpers.rb
|
112
118
|
- spec/support/model_helpers.rb
|
113
119
|
- spec/support/with_contexts_helpers.rb
|
120
|
+
- spec/warp/action_matchers/create_matcher_spec.rb
|
114
121
|
- spec/warp/controller_matchers/assign_matcher_spec.rb
|
115
122
|
- spec/warp/controller_matchers/set_flash_matcher_spec.rb
|
123
|
+
- spec/warp/instrument_spec.rb
|
116
124
|
- spec/warp/model_helpers/association_matcher_spec.rb
|
117
125
|
- spec/warp/model_helpers/attribute_matcher_spec.rb
|
118
126
|
- spec/warp/model_helpers/validation_matcher_spec.rb
|