warp 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +8 -6
- data/lib/warp/controller_matchers/assign_matcher.rb +12 -11
- data/lib/warp/controller_matchers/set_flash_matcher.rb +5 -4
- data/lib/warp/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/support/controller_helpers.rb +5 -3
- data/spec/support/with_contexts_helpers.rb +32 -0
- data/spec/warp/controller_matchers/assign_matcher_spec.rb +168 -149
- data/spec/warp/controller_matchers/set_flash_matcher_spec.rb +72 -53
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a26f9c24ab61368b029824ef4d7da7224830142b
|
4
|
+
data.tar.gz: 1b26fa712ddd38e5e70ee757920f4ee8a2e89ed0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a851430a6ff0293d2e4ed1978aae6afc1111af4a826ea7ce0fe006bcf64eea0279c2de0dd9f523b17df122f495a53a4427d3b5a3d87b3c0781aad9e05f82160
|
7
|
+
data.tar.gz: 13504117019ea432a0947c9b6601c8ace8d90d9113a001f33becd1103e03b5b18aec2495d2959dd9f8d53f705cb41e96012f2d0822082e300b6e265e92f8029e
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Warp
|
2
2
|
|
3
3
|
[](https://travis-ci.org/thomasfedb/warp)
|
4
|
+
[](http://rubygems.org/gems/warp)
|
5
|
+
[](https://codeclimate.com/github/thomasfedb/warp)
|
4
6
|
|
5
7
|
RSpec Matchers to simplify writing unit and feature tests for your Rails applications.
|
6
8
|
|
@@ -18,7 +20,7 @@ And then execute:
|
|
18
20
|
|
19
21
|
## Usage
|
20
22
|
|
21
|
-
### assigns(
|
23
|
+
### assigns(key)
|
22
24
|
|
23
25
|
Ensures that the specific assign is set:
|
24
26
|
|
@@ -26,7 +28,7 @@ Ensures that the specific assign is set:
|
|
26
28
|
specify { expect(controller).to assign(:posts) }
|
27
29
|
```
|
28
30
|
|
29
|
-
### assigns(
|
31
|
+
### assigns(key).with(object)
|
30
32
|
|
31
33
|
Ensures that the specific assign is set with the specified value:
|
32
34
|
|
@@ -34,7 +36,7 @@ Ensures that the specific assign is set with the specified value:
|
|
34
36
|
specify { expect(controller).to assign(:posts).with(posts) }
|
35
37
|
```
|
36
38
|
|
37
|
-
### assigns(
|
39
|
+
### assigns(key).with_a(klass)
|
38
40
|
|
39
41
|
Ensures that the specific assign is set with an instance of the specified class:
|
40
42
|
|
@@ -42,7 +44,7 @@ Ensures that the specific assign is set with an instance of the specified class:
|
|
42
44
|
specify { expect(controller).to assign(:post).with_a(Post) }
|
43
45
|
```
|
44
46
|
|
45
|
-
### assigns(
|
47
|
+
### assigns(key).with_a_new(klass)
|
46
48
|
|
47
49
|
Ensures that the specific assign is set with a instance of the specified class that is not persisted:
|
48
50
|
|
@@ -50,14 +52,14 @@ Ensures that the specific assign is set with a instance of the specified class t
|
|
50
52
|
specify { expect(controller).to assign(:post).with_a_new(Post) }
|
51
53
|
```
|
52
54
|
|
53
|
-
### set_flash(
|
55
|
+
### set_flash(key)
|
54
56
|
|
55
57
|
Ensure that the specific flash key is set:
|
56
58
|
|
57
59
|
```ruby
|
58
60
|
specify { expect(controller).to set_flash(:notice) }
|
59
61
|
```
|
60
|
-
### set_flash(
|
62
|
+
### set_flash(key).to(value)
|
61
63
|
|
62
64
|
Ensure that the specific flash key is set:
|
63
65
|
|
@@ -6,8 +6,9 @@ module Warp
|
|
6
6
|
attr_reader :assign_key, :assign_with, :assign_with_a, :assign_with_a_new
|
7
7
|
attr_reader :controller, :failure_message, :failure_message_when_negated, :description
|
8
8
|
|
9
|
-
def initialize(assign_key)
|
9
|
+
def initialize(assign_key, controller)
|
10
10
|
@assign_key = assign_key
|
11
|
+
@controller = controller
|
11
12
|
end
|
12
13
|
|
13
14
|
def with(assign_eq)
|
@@ -25,8 +26,8 @@ module Warp
|
|
25
26
|
self
|
26
27
|
end
|
27
28
|
|
28
|
-
def matches?(
|
29
|
-
@controller =
|
29
|
+
def matches?(actual)
|
30
|
+
@controller = actual if actual.is_a?(ActionController::Metal)
|
30
31
|
|
31
32
|
if multiple_assertions?
|
32
33
|
raise "Only one of .with, .with_a, and .with_a_new can be used with the assigns matcher."
|
@@ -49,9 +50,9 @@ module Warp
|
|
49
50
|
end
|
50
51
|
|
51
52
|
def check_assign_with
|
52
|
-
@description = "assign @#{assign_key} with #{assign_with
|
53
|
-
@failure_message = "expected @#{assign_key} to be assigned with #{assign_with
|
54
|
-
@failure_message_when_negated = "expected @#{assign_key} to not be assigned with #{assign_with
|
53
|
+
@description = "assign @#{assign_key} with #{description_of(assign_with)}"
|
54
|
+
@failure_message = "expected @#{assign_key} to be assigned with #{description_of(assign_with)} but was assigned with #{assign_value.inspect}"
|
55
|
+
@failure_message_when_negated = "expected @#{assign_key} to not be assigned with #{description_of(assign_with)}"
|
55
56
|
|
56
57
|
values_match?(assign_with, assign_value)
|
57
58
|
end
|
@@ -61,7 +62,7 @@ module Warp
|
|
61
62
|
@failure_message = "expected @#{assign_key} to be assigned with an instance of #{assign_with_a.name} but was assigned with an instance of #{assign_value.class.name}"
|
62
63
|
@failure_message_when_negated = "expected @#{assign_key} to not be assigned with an instance of #{assign_with_a.name}"
|
63
64
|
|
64
|
-
has_ancestor?(
|
65
|
+
has_ancestor?(assign_with_a, assign_value)
|
65
66
|
end
|
66
67
|
|
67
68
|
def check_assign_with_a_new
|
@@ -69,7 +70,7 @@ module Warp
|
|
69
70
|
@failure_message = "expected @#{assign_key} to be assigned with a new instance of #{assign_with_a_new.name} but was assigned with a #{assign_value.persisted? ? "persisted" : "new"} instance of #{assign_value.class.name}"
|
70
71
|
@failure_message_when_negated = "expected @#{assign_key} to not be assigned with a new instance of #{assign_with_a_new.name}"
|
71
72
|
|
72
|
-
has_ancestor?(
|
73
|
+
has_ancestor?(assign_with_a_new, assign_value) && values_match?(false, assign_value.persisted?)
|
73
74
|
end
|
74
75
|
|
75
76
|
def assign_value
|
@@ -80,13 +81,13 @@ module Warp
|
|
80
81
|
[@assign_with, @assign_with_a, @assign_with_a_new].compact.size > 1
|
81
82
|
end
|
82
83
|
|
83
|
-
def has_ancestor?(
|
84
|
-
|
84
|
+
def has_ancestor?(expected_class, actual)
|
85
|
+
actual.class.ancestors.any? {|ancestor| values_match?(expected_class, ancestor) }
|
85
86
|
end
|
86
87
|
end
|
87
88
|
|
88
89
|
def assign(assign_key)
|
89
|
-
AssignMatcher.new(assign_key)
|
90
|
+
AssignMatcher.new(assign_key, controller)
|
90
91
|
end
|
91
92
|
end
|
92
93
|
end
|
@@ -6,8 +6,9 @@ module Warp
|
|
6
6
|
attr_reader :flash_key, :expected_flash_value
|
7
7
|
attr_reader :controller, :failure_message, :failure_message_when_negated, :description
|
8
8
|
|
9
|
-
def initialize(flash_key)
|
9
|
+
def initialize(flash_key, controller)
|
10
10
|
@flash_key = flash_key
|
11
|
+
@controller = controller
|
11
12
|
end
|
12
13
|
|
13
14
|
def to(expected_flash_value)
|
@@ -15,8 +16,8 @@ module Warp
|
|
15
16
|
self
|
16
17
|
end
|
17
18
|
|
18
|
-
def matches?(
|
19
|
-
@controller =
|
19
|
+
def matches?(actual)
|
20
|
+
@controller = actual if actual.is_a?(ActionController::Metal)
|
20
21
|
|
21
22
|
if expected_flash_value
|
22
23
|
@description = "set flash[:#{flash_key}] to #{expected_flash_value.inspect}"
|
@@ -43,7 +44,7 @@ module Warp
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def set_flash(flash_key)
|
46
|
-
SetFlashMatcher.new(flash_key)
|
47
|
+
SetFlashMatcher.new(flash_key, controller)
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
data/lib/warp/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module ControllerHelpers
|
2
|
-
def build_controller
|
2
|
+
def build_controller(name = :controller)
|
3
|
+
let(:controller_name) { name }
|
4
|
+
|
3
5
|
let(:controller_class) do
|
4
6
|
Class.new(ActionController::Metal).tap do |klass|
|
5
7
|
klass.instance_eval do
|
@@ -26,7 +28,7 @@ module ControllerHelpers
|
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
let(
|
31
|
+
let(name) do
|
30
32
|
controller_class.new.tap do |controller|
|
31
33
|
controller.instance_variable_set(:@_request, request)
|
32
34
|
end
|
@@ -40,7 +42,7 @@ module ControllerHelpers
|
|
40
42
|
render text: ""
|
41
43
|
end
|
42
44
|
|
43
|
-
|
45
|
+
send(controller_name).dispatch(:index, request)
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module WithContextsHelpers
|
2
|
+
class WithContextsBuilder
|
3
|
+
attr_accessor :contexts, :examples, :group
|
4
|
+
|
5
|
+
def initialize(group)
|
6
|
+
@contexts = {}
|
7
|
+
@group = group
|
8
|
+
end
|
9
|
+
|
10
|
+
def context(name, &blk)
|
11
|
+
self.contexts[name] = blk
|
12
|
+
end
|
13
|
+
|
14
|
+
def behaviour(&blk)
|
15
|
+
self.examples = blk
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute
|
19
|
+
contexts.each do |name, blk|
|
20
|
+
context = group.context(name)
|
21
|
+
context.instance_eval(&blk)
|
22
|
+
context.instance_eval(&examples)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def with_contexts(&blk)
|
28
|
+
builder = WithContextsBuilder.new(self)
|
29
|
+
builder.instance_eval(&blk)
|
30
|
+
builder.execute
|
31
|
+
end
|
32
|
+
end
|
@@ -1,211 +1,230 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Warp::ControllerMatchers::AssignMatcher do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
subject { super().matches?(controller); super().description }
|
10
|
-
|
11
|
-
specify { expect(subject).to eq "assign @assign" }
|
12
|
-
end
|
13
|
-
|
14
|
-
context "when assigned" do
|
15
|
-
controller_action do
|
16
|
-
@assign = Object.new
|
17
|
-
end
|
18
|
-
|
19
|
-
specify { expect(subject).to match(controller) }
|
20
|
-
|
21
|
-
describe "#failure_message_when_negated" do
|
22
|
-
subject { super().matches?(controller); super().failure_message_when_negated }
|
23
|
-
|
24
|
-
specify { expect(subject).to eq "expected @assign to not be assigned" }
|
25
|
-
end
|
26
|
-
end
|
4
|
+
with_contexts do
|
5
|
+
context "with implicit controller" do
|
6
|
+
build_controller(:controller)
|
7
|
+
|
8
|
+
let(:_controller) { controller }
|
27
9
|
|
28
|
-
|
29
|
-
controller_action do
|
30
|
-
# no assign
|
10
|
+
subject { matcher.tap {|m| m.matches?(Object.new) } }
|
31
11
|
end
|
32
|
-
|
33
|
-
specify { expect(subject).to_not match(controller) }
|
34
12
|
|
35
|
-
|
36
|
-
|
13
|
+
context "with explicit controller" do
|
14
|
+
build_controller(:other_controller)
|
15
|
+
let(:controller) { double("fake controller") }
|
37
16
|
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
17
|
+
let(:_controller) { other_controller }
|
41
18
|
|
42
|
-
|
43
|
-
controller_action do
|
44
|
-
@assign = spec.actual_assign_value
|
19
|
+
subject { matcher.tap {|m| m.matches?(other_controller) } }
|
45
20
|
end
|
21
|
+
|
22
|
+
behaviour do
|
23
|
+
let(:matcher) { assign(:assign) }
|
46
24
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
subject { super().with(expected_assign_value) }
|
25
|
+
describe "#description" do
|
26
|
+
subject { super().description }
|
51
27
|
|
52
|
-
|
53
|
-
|
28
|
+
specify { expect(subject).to eq "assign @assign" }
|
29
|
+
end
|
54
30
|
|
55
|
-
|
56
|
-
|
31
|
+
context "when assigned" do
|
32
|
+
controller_action do
|
33
|
+
@assign = Object.new
|
34
|
+
end
|
57
35
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
subject { super().matches?(controller); super().failure_message_when_negated }
|
36
|
+
specify { expect(subject).to match(_controller) }
|
37
|
+
|
38
|
+
describe "#failure_message_when_negated" do
|
39
|
+
subject { super().failure_message_when_negated }
|
63
40
|
|
64
|
-
|
41
|
+
specify { expect(subject).to eq "expected @assign to not be assigned" }
|
42
|
+
end
|
65
43
|
end
|
66
|
-
end
|
67
44
|
|
68
|
-
|
69
|
-
|
45
|
+
context "when not assigned" do
|
46
|
+
controller_action do
|
47
|
+
# no assign
|
48
|
+
end
|
70
49
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
50
|
+
specify { expect(subject).to_not match(_controller) }
|
51
|
+
|
52
|
+
describe "#failure_message" do
|
53
|
+
subject { super().failure_message }
|
75
54
|
|
76
|
-
|
55
|
+
specify { expect(subject).to eq "expected @assign to be assigned" }
|
56
|
+
end
|
77
57
|
end
|
78
|
-
end
|
79
|
-
end
|
80
58
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
59
|
+
describe "#with" do
|
60
|
+
controller_action do
|
61
|
+
@assign = spec.actual_assign_value
|
62
|
+
end
|
85
63
|
|
86
|
-
|
87
|
-
|
64
|
+
let(:actual_assign_value) { "foobar" }
|
65
|
+
let(:expected_assign_value) { "foobar" }
|
88
66
|
|
89
|
-
|
67
|
+
let(:matcher) { super().with(expected_assign_value) }
|
90
68
|
|
91
|
-
|
92
|
-
|
69
|
+
describe "#description" do
|
70
|
+
subject { super().description }
|
93
71
|
|
94
|
-
|
95
|
-
|
72
|
+
specify { expect(subject).to eq "assign @assign with #{expected_assign_value.inspect}" }
|
73
|
+
end
|
96
74
|
|
97
|
-
|
98
|
-
|
75
|
+
context "with the right value" do
|
76
|
+
specify { expect(subject).to match(_controller) }
|
99
77
|
|
100
|
-
|
101
|
-
|
78
|
+
describe "#failure_message_when_negated" do
|
79
|
+
subject { super().failure_message_when_negated }
|
102
80
|
|
103
|
-
|
104
|
-
|
105
|
-
|
81
|
+
specify { expect(subject).to eq "expected @assign to not be assigned with #{expected_assign_value.inspect}" }
|
82
|
+
end
|
83
|
+
end
|
106
84
|
|
107
|
-
|
108
|
-
|
85
|
+
context "with the wrong value" do
|
86
|
+
let(:expected_assign_value) { "foobaz" }
|
109
87
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
88
|
+
specify { expect(subject).to_not match(_controller) }
|
89
|
+
|
90
|
+
describe "#failure_message" do
|
91
|
+
subject { super().failure_message }
|
114
92
|
|
115
|
-
|
116
|
-
|
93
|
+
specify { expect(subject).to eq "expected @assign to be assigned with #{expected_assign_value.inspect} but was assigned with #{actual_assign_value.inspect}" }
|
94
|
+
end
|
95
|
+
end
|
117
96
|
end
|
118
|
-
end
|
119
|
-
end
|
120
97
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
98
|
+
describe "#with_a" do
|
99
|
+
controller_action do
|
100
|
+
@assign = spec.actual_assign_class.new
|
101
|
+
end
|
125
102
|
|
126
|
-
|
127
|
-
|
128
|
-
Class.new.tap do |klass|
|
129
|
-
allow(klass).to receive(:name) { "FooClass" }
|
130
|
-
allow_any_instance_of(klass).to receive(:persisted?) { actual_persisted? }
|
131
|
-
end
|
132
|
-
end
|
103
|
+
let(:actual_assign_class) { Class.new.tap {|klass| allow(klass).to receive(:name) { "FooClass" } } }
|
104
|
+
let(:expected_assign_class) { actual_assign_class }
|
133
105
|
|
134
|
-
|
106
|
+
let(:matcher) { super().with_a(expected_assign_class) }
|
135
107
|
|
136
|
-
|
108
|
+
describe "#description" do
|
109
|
+
subject { super().description }
|
137
110
|
|
138
|
-
|
139
|
-
|
111
|
+
specify { expect(subject).to eq "assign @assign with an instance of #{expected_assign_class.name}" }
|
112
|
+
end
|
140
113
|
|
141
|
-
|
142
|
-
|
114
|
+
context "with the right class" do
|
115
|
+
specify { expect(subject).to match(_controller) }
|
116
|
+
|
117
|
+
describe "#failure_message_when_negated" do
|
118
|
+
subject { super().failure_message_when_negated }
|
143
119
|
|
144
|
-
|
145
|
-
|
120
|
+
specify { expect(subject).to eq "expected @assign to not be assigned with an instance of #{expected_assign_class.name}" }
|
121
|
+
end
|
122
|
+
end
|
146
123
|
|
147
|
-
|
148
|
-
|
124
|
+
context "with the wrong class" do
|
125
|
+
let(:expected_assign_class) { Class.new.tap {|klass| allow(klass).to receive(:name) { "BarClass" } } }
|
149
126
|
|
150
|
-
|
151
|
-
|
127
|
+
specify { expect(subject).to_not match(_controller) }
|
128
|
+
|
129
|
+
describe "#failure_message" do
|
130
|
+
subject { super().failure_message }
|
152
131
|
|
153
|
-
|
132
|
+
specify { expect(subject).to eq "expected @assign to be assigned with an instance of #{expected_assign_class.name} but was assigned with an instance of #{actual_assign_class.name}"
|
133
|
+
}
|
134
|
+
end
|
154
135
|
end
|
155
136
|
end
|
156
137
|
|
157
|
-
|
138
|
+
describe "#with_a_new" do
|
139
|
+
controller_action do
|
140
|
+
@assign = spec.actual_assign_class.new
|
141
|
+
end
|
142
|
+
|
143
|
+
let(:actual_persisted?) { false }
|
158
144
|
let(:actual_assign_class) do
|
159
|
-
Class.new
|
145
|
+
Class.new.tap do |klass|
|
146
|
+
allow(klass).to receive(:name) { "FooClass" }
|
147
|
+
allow_any_instance_of(klass).to receive(:persisted?) { actual_persisted? }
|
148
|
+
end
|
160
149
|
end
|
161
150
|
|
162
|
-
|
151
|
+
let(:expected_assign_class) { actual_assign_class }
|
163
152
|
|
164
|
-
|
165
|
-
subject { super().matches?(controller); super().failure_message_when_negated }
|
153
|
+
let(:matcher) { super().with_a_new(expected_assign_class) }
|
166
154
|
|
167
|
-
|
168
|
-
|
169
|
-
end
|
155
|
+
describe "#description" do
|
156
|
+
subject { super().description }
|
170
157
|
|
171
|
-
|
172
|
-
|
158
|
+
specify { expect(subject).to eq "assign @assign with a new instance of #{expected_assign_class.name}" }
|
159
|
+
end
|
173
160
|
|
174
|
-
|
175
|
-
|
176
|
-
describe "#failure_message" do
|
177
|
-
subject { super().matches?(controller); super().failure_message }
|
161
|
+
context "with a new object" do
|
162
|
+
let(:actual_persisted?) { false }
|
178
163
|
|
179
|
-
|
180
|
-
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
164
|
+
context "with the right class" do
|
165
|
+
specify { expect(subject).to match(_controller) }
|
184
166
|
|
185
|
-
|
186
|
-
|
167
|
+
describe "#failure_message_when_negated" do
|
168
|
+
subject { super().failure_message_when_negated }
|
187
169
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
170
|
+
specify { expect(subject).to eq "expected @assign to not be assigned with a new instance of #{expected_assign_class.name}" }
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context "with a descendant class" do
|
175
|
+
let(:actual_assign_class) do
|
176
|
+
Class.new(super())
|
177
|
+
end
|
178
|
+
|
179
|
+
specify { expect(subject).to match(_controller) }
|
180
|
+
|
181
|
+
describe "#failure_message_when_negated" do
|
182
|
+
subject { super().failure_message_when_negated }
|
193
183
|
|
194
|
-
|
195
|
-
|
184
|
+
specify { expect(subject).to eq "expected @assign to not be assigned with a new instance of #{expected_assign_class.name}" }
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context "with the wrong class" do
|
189
|
+
let(:expected_assign_class) { Class.new.tap {|klass| allow(klass).to receive(:name) { "BarClass" } } }
|
190
|
+
|
191
|
+
specify { expect(subject).to_not match(_controller) }
|
192
|
+
|
193
|
+
describe "#failure_message" do
|
194
|
+
subject { super().failure_message }
|
195
|
+
|
196
|
+
specify { expect(subject).to eq "expected @assign to be assigned with a new instance of #{expected_assign_class.name} but was assigned with a new instance of #{actual_assign_class.name}"
|
197
|
+
}
|
198
|
+
end
|
199
|
+
end
|
196
200
|
end
|
197
|
-
end
|
198
201
|
|
199
|
-
|
200
|
-
|
202
|
+
context "with a persisted object" do
|
203
|
+
let(:actual_persisted?) { true }
|
201
204
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
205
|
+
context "with the right class" do
|
206
|
+
specify { expect(subject).to_not match(_controller) }
|
207
|
+
|
208
|
+
describe "#failure_message" do
|
209
|
+
subject { super().failure_message }
|
210
|
+
|
211
|
+
specify { expect(subject).to eq "expected @assign to be assigned with a new instance of #{expected_assign_class.name} but was assigned with a persisted instance of #{actual_assign_class.name}"
|
212
|
+
}
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
context "with the wrong class" do
|
217
|
+
let(:expected_assign_class) { Class.new.tap {|klass| allow(klass).to receive(:name) { "BarClass" } } }
|
218
|
+
|
219
|
+
specify { expect(subject).to_not match(_controller) }
|
220
|
+
|
221
|
+
describe "#failure_message" do
|
222
|
+
subject { super().failure_message }
|
206
223
|
|
207
|
-
|
208
|
-
|
224
|
+
specify { expect(subject).to eq "expected @assign to be assigned with a new instance of #{expected_assign_class.name} but was assigned with a persisted instance of #{actual_assign_class.name}"
|
225
|
+
}
|
226
|
+
end
|
227
|
+
end
|
209
228
|
end
|
210
229
|
end
|
211
230
|
end
|
@@ -1,80 +1,99 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Warp::ControllerMatchers::SetFlashMatcher do
|
4
|
-
|
4
|
+
with_contexts do
|
5
|
+
context "with implicit controller" do
|
6
|
+
build_controller(:controller)
|
7
|
+
|
8
|
+
let(:_controller) { controller }
|
5
9
|
|
6
|
-
|
10
|
+
subject { matcher.tap {|m| m.matches?(Object.new) } }
|
11
|
+
end
|
12
|
+
|
13
|
+
context "with explicit controller" do
|
14
|
+
build_controller(:other_controller)
|
15
|
+
let(:controller) { double("fake controller") }
|
7
16
|
|
8
|
-
|
17
|
+
let(:_controller) { other_controller }
|
9
18
|
|
10
|
-
|
11
|
-
|
19
|
+
subject { matcher.tap {|m| m.matches?(other_controller) } }
|
20
|
+
end
|
12
21
|
|
13
|
-
|
14
|
-
|
22
|
+
behaviour do
|
23
|
+
let(:flash_key) { [:notice, :error].sample }
|
15
24
|
|
16
|
-
|
17
|
-
let(:actual_flash_value) { Object.new }
|
25
|
+
let(:matcher) { set_flash(flash_key) }
|
18
26
|
|
19
|
-
|
20
|
-
|
21
|
-
end
|
27
|
+
describe "#description" do
|
28
|
+
subject { super().description }
|
22
29
|
|
23
|
-
|
24
|
-
|
25
|
-
describe "#failure_message_when_negated" do
|
26
|
-
subject { super().matches?(controller); super().failure_message_when_negated }
|
30
|
+
specify { expect(subject).to eq "set flash[:#{flash_key}]" }
|
31
|
+
end
|
27
32
|
|
28
|
-
|
29
|
-
|
30
|
-
end
|
33
|
+
context "with a flash set" do
|
34
|
+
let(:actual_flash_value) { Object.new }
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
describe "#failure_message" do
|
36
|
-
subject { super().matches?(controller); super().failure_message }
|
36
|
+
controller_action do
|
37
|
+
flash[spec.flash_key] = spec.actual_flash_value
|
38
|
+
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
specify { expect(subject).to match(_controller) }
|
41
|
+
|
42
|
+
describe "#failure_message_when_negated" do
|
43
|
+
subject { super().failure_message_when_negated }
|
41
44
|
|
42
|
-
|
43
|
-
|
45
|
+
specify { expect(subject).to eq "expected flash[:#{flash_key}] to not be set" }
|
46
|
+
end
|
47
|
+
end
|
44
48
|
|
45
|
-
|
49
|
+
context "with no flash set" do
|
50
|
+
specify { expect(subject).to_not match(_controller) }
|
51
|
+
|
52
|
+
describe "#failure_message" do
|
53
|
+
subject { super().failure_message }
|
46
54
|
|
47
|
-
|
48
|
-
|
55
|
+
specify { expect(subject).to eq "expected flash[:#{flash_key}] to be set" }
|
56
|
+
end
|
57
|
+
end
|
49
58
|
|
50
|
-
|
51
|
-
|
59
|
+
describe "#to" do
|
60
|
+
let(:expected_flash_value) { Object.new }
|
52
61
|
|
53
|
-
|
54
|
-
let(:actual_flash_value) { expected_flash_value }
|
62
|
+
let(:matcher) { super().to(expected_flash_value) }
|
55
63
|
|
56
|
-
|
57
|
-
|
58
|
-
end
|
64
|
+
describe "#description" do
|
65
|
+
subject { super().description }
|
59
66
|
|
60
|
-
|
61
|
-
|
62
|
-
describe "#failure_message_when_negated" do
|
63
|
-
subject { super().matches?(controller); super().failure_message_when_negated }
|
67
|
+
specify { expect(subject).to eq "set flash[:#{flash_key}] to #{expected_flash_value.inspect}" }
|
68
|
+
end
|
64
69
|
|
65
|
-
|
66
|
-
|
67
|
-
end
|
70
|
+
context "with expexted flash value" do
|
71
|
+
let(:actual_flash_value) { expected_flash_value }
|
68
72
|
|
69
|
-
|
70
|
-
|
73
|
+
controller_action do
|
74
|
+
flash[spec.flash_key] = spec.actual_flash_value
|
75
|
+
end
|
71
76
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
77
|
+
specify { expect(subject).to match(_controller) }
|
78
|
+
|
79
|
+
describe "#failure_message_when_negated" do
|
80
|
+
subject { super().failure_message_when_negated }
|
81
|
+
|
82
|
+
specify { expect(subject).to eq "expected flash[:#{flash_key}] to not be set to #{expected_flash_value.inspect}" }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context "with unexpexted flash value" do
|
87
|
+
let(:actual_flash_value) { Object.new }
|
88
|
+
|
89
|
+
specify { expect(subject).to_not match(_controller) }
|
90
|
+
|
91
|
+
describe "#failure_message" do
|
92
|
+
subject { super().failure_message }
|
76
93
|
|
77
|
-
|
94
|
+
specify { expect(subject).to eq "expected flash[:#{flash_key}] to be set to #{expected_flash_value.inspect}" }
|
95
|
+
end
|
96
|
+
end
|
78
97
|
end
|
79
98
|
end
|
80
99
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
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-01-
|
11
|
+
date: 2014-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- ".ruby-gemset"
|
92
92
|
- ".ruby-version"
|
93
93
|
- ".travis.yml"
|
94
|
+
- CHANGELOG.md
|
94
95
|
- Gemfile
|
95
96
|
- Guardfile
|
96
97
|
- LICENSE
|
@@ -107,6 +108,7 @@ files:
|
|
107
108
|
- spec/spec_helper.rb
|
108
109
|
- spec/support/controller_helpers.rb
|
109
110
|
- spec/support/match_helpers.rb
|
111
|
+
- spec/support/with_contexts_helpers.rb
|
110
112
|
- spec/warp/controller_matchers/assign_matcher_spec.rb
|
111
113
|
- spec/warp/controller_matchers/set_flash_matcher_spec.rb
|
112
114
|
- warp.gemspec
|
@@ -138,5 +140,6 @@ test_files:
|
|
138
140
|
- spec/spec_helper.rb
|
139
141
|
- spec/support/controller_helpers.rb
|
140
142
|
- spec/support/match_helpers.rb
|
143
|
+
- spec/support/with_contexts_helpers.rb
|
141
144
|
- spec/warp/controller_matchers/assign_matcher_spec.rb
|
142
145
|
- spec/warp/controller_matchers/set_flash_matcher_spec.rb
|