warp 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +21 -0
- data/Gemfile +15 -0
- data/Guardfile +5 -0
- data/LICENSE +22 -0
- data/README.md +75 -0
- data/Rakefile +1 -0
- data/gemfiles/rails-3.2 +17 -0
- data/gemfiles/rails-4.0 +17 -0
- data/gemfiles/rails-4.1 +18 -0
- data/lib/warp/controller_matchers/assign_matcher.rb +92 -0
- data/lib/warp/controller_matchers/set_flash_matcher.rb +49 -0
- data/lib/warp/controller_matchers.rb +6 -0
- data/lib/warp/version.rb +3 -0
- data/lib/warp.rb +5 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/support/controller_helpers.rb +46 -0
- data/spec/support/match_helpers.rb +18 -0
- data/spec/warp/controller_matchers/assign_matcher_spec.rb +213 -0
- data/spec/warp/controller_matchers/set_flash_matcher_spec.rb +81 -0
- data/warp.gemspec +29 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c3ced099297c6651735bef5b460ba7d59ca44ea7
|
4
|
+
data.tar.gz: a358f43f18681cd99088c1669ba3ff9dfdc8f98f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e256fafcd4a89e333ee478fdff1a8fbc3c5fca8bb6cd84e666db9279bf1f0339d3cb8c3541b61d0b738051e6357a5c470bd60fc7b524875baad3fd63cea7ad3d
|
7
|
+
data.tar.gz: 4163e2f6b8e369414508e0b0b59b160a316deaa5f0c5fda5a10ef4097299482221bf492c4cdbb563ac69f1da5af001b6084ccf58b196b2966e84b76cb0fc1de4
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
warp
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.1.0
|
data/.travis.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.2
|
4
|
+
- 1.9.3
|
5
|
+
- 2.0.0
|
6
|
+
- 2.1.0
|
7
|
+
gemfile:
|
8
|
+
- gemfiles/rails-3.2
|
9
|
+
- gemfiles/rails-4.0
|
10
|
+
- gemfiles/rails-4.1
|
11
|
+
- Gemfile
|
12
|
+
matrix:
|
13
|
+
exclude:
|
14
|
+
- rvm: 1.9.2
|
15
|
+
gemfile: gemfiles/rails-4.0
|
16
|
+
- rvm: 1.9.2
|
17
|
+
gemfile: gemfiles/rails-4.1
|
18
|
+
- rvm: 1.9.2
|
19
|
+
gemfile: Gemfile
|
20
|
+
bundler_args: --without tools
|
21
|
+
script: bundle exec rspec
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
gem "rspec", git: "https://github.com/rspec/rspec.git"
|
6
|
+
gem "rspec-core", git: "https://github.com/rspec/rspec-core.git"
|
7
|
+
gem "rspec-expectations", git: "https://github.com/rspec/rspec-expectations.git"
|
8
|
+
gem "rspec-mocks", git: "https://github.com/rspec/rspec-mocks.git"
|
9
|
+
gem "rspec-support", git: "https://github.com/rspec/rspec-support.git"
|
10
|
+
|
11
|
+
group :tools do
|
12
|
+
gem "guard"
|
13
|
+
gem "guard-rspec"
|
14
|
+
gem "byebug"
|
15
|
+
end
|
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Thomas Drake-Brockman
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Warp
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/thomasfedb/warp.png)](https://travis-ci.org/thomasfedb/warp)
|
4
|
+
|
5
|
+
RSpec Matchers to simplify writing unit and feature tests for your Rails applications.
|
6
|
+
|
7
|
+
Compatible with Ruby 1.9.2 and greater, and Rails 3.2 and greater.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem "warp"
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### assigns(:key)
|
22
|
+
|
23
|
+
Ensures that the specific assign is set:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
specify { expect(controller).to assign(:posts) }
|
27
|
+
```
|
28
|
+
|
29
|
+
### assigns(:key).with
|
30
|
+
|
31
|
+
Ensures that the specific assign is set with the specified value:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
specify { expect(controller).to assign(:posts).with(posts) }
|
35
|
+
```
|
36
|
+
|
37
|
+
### assigns(:key).with_a
|
38
|
+
|
39
|
+
Ensures that the specific assign is set with an instance of the specified class:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
specify { expect(controller).to assign(:post).with_a(Post) }
|
43
|
+
```
|
44
|
+
|
45
|
+
### assigns(:key).with_a_new
|
46
|
+
|
47
|
+
Ensures that the specific assign is set with a instance of the specified class that is not persisted:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
specify { expect(controller).to assign(:post).with_a_new(Post) }
|
51
|
+
```
|
52
|
+
|
53
|
+
### set_flash(:key)
|
54
|
+
|
55
|
+
Ensure that the specific flash key is set:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
specify { expect(controller).to set_flash(:notice) }
|
59
|
+
```
|
60
|
+
### set_flash(:key).to("expected value")
|
61
|
+
|
62
|
+
Ensure that the specific flash key is set:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
specify { expect(controller).to set_flash(:notice).to("Your order has been processed.") }
|
66
|
+
```
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
1. Fork it
|
71
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
72
|
+
3. Add your feature and specs.
|
73
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
74
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
75
|
+
6. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/gemfiles/rails-3.2
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem "warp", :path=>"../"
|
4
|
+
|
5
|
+
gem "bundler", "~> 1.5.1"
|
6
|
+
gem "rake"
|
7
|
+
|
8
|
+
gem "activesupport", "~> 3.2"
|
9
|
+
gem "actionpack", "~> 3.2"
|
10
|
+
|
11
|
+
gem "rspec", git: "https://github.com/rspec/rspec.git"
|
12
|
+
gem "rspec-core", git: "https://github.com/rspec/rspec-core.git"
|
13
|
+
gem "rspec-expectations", git: "https://github.com/rspec/rspec-expectations.git"
|
14
|
+
gem "rspec-mocks", git: "https://github.com/rspec/rspec-mocks.git"
|
15
|
+
gem "rspec-support", git: "https://github.com/rspec/rspec-support.git"
|
16
|
+
|
17
|
+
gem "fuubar"
|
data/gemfiles/rails-4.0
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem "warp", :path=>"../"
|
4
|
+
|
5
|
+
gem "bundler", "~> 1.5.1"
|
6
|
+
gem "rake"
|
7
|
+
|
8
|
+
gem "activesupport", "~> 4.0"
|
9
|
+
gem "actionpack", "~> 4.0"
|
10
|
+
|
11
|
+
gem "rspec", git: "https://github.com/rspec/rspec.git"
|
12
|
+
gem "rspec-core", git: "https://github.com/rspec/rspec-core.git"
|
13
|
+
gem "rspec-expectations", git: "https://github.com/rspec/rspec-expectations.git"
|
14
|
+
gem "rspec-mocks", git: "https://github.com/rspec/rspec-mocks.git"
|
15
|
+
gem "rspec-support", git: "https://github.com/rspec/rspec-support.git"
|
16
|
+
|
17
|
+
gem "fuubar"
|
data/gemfiles/rails-4.1
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem "warp", :path=>"../"
|
4
|
+
|
5
|
+
gem "bundler", "~> 1.5.1"
|
6
|
+
gem "rake"
|
7
|
+
|
8
|
+
gem "activesupport", "4.1.0.beta1"
|
9
|
+
gem "actionpack", "4.1.0.beta1"
|
10
|
+
gem "actionview", "4.1.0.beta1", require: "action_view"
|
11
|
+
|
12
|
+
gem "rspec", git: "https://github.com/rspec/rspec.git"
|
13
|
+
gem "rspec-core", git: "https://github.com/rspec/rspec-core.git"
|
14
|
+
gem "rspec-expectations", git: "https://github.com/rspec/rspec-expectations.git"
|
15
|
+
gem "rspec-mocks", git: "https://github.com/rspec/rspec-mocks.git"
|
16
|
+
gem "rspec-support", git: "https://github.com/rspec/rspec-support.git"
|
17
|
+
|
18
|
+
gem "fuubar"
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module Warp
|
2
|
+
module ControllerMatchers
|
3
|
+
class AssignMatcher
|
4
|
+
include RSpec::Matchers::Composable
|
5
|
+
|
6
|
+
attr_reader :assign_key, :assign_with, :assign_with_a, :assign_with_a_new
|
7
|
+
attr_reader :controller, :failure_message, :failure_message_when_negated, :description
|
8
|
+
|
9
|
+
def initialize(assign_key)
|
10
|
+
@assign_key = assign_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def with(assign_eq)
|
14
|
+
@assign_with = assign_eq
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def with_a(assign_class)
|
19
|
+
@assign_with_a = assign_class
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def with_a_new(assign_class)
|
24
|
+
@assign_with_a_new = assign_class
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def matches?(controller)
|
29
|
+
@controller = controller
|
30
|
+
|
31
|
+
if multiple_assertions?
|
32
|
+
raise "Only one of .with, .with_a, and .with_a_new can be used with the assigns matcher."
|
33
|
+
end
|
34
|
+
|
35
|
+
return check_assign_with if assign_with
|
36
|
+
return check_assign_with_a if assign_with_a
|
37
|
+
return check_assign_with_a_new if assign_with_a_new
|
38
|
+
return check_assign
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def check_assign
|
44
|
+
@description = "assign @#{assign_key}"
|
45
|
+
@failure_message = "expected @#{assign_key} to be assigned"
|
46
|
+
@failure_message_when_negated = "expected @#{assign_key} to not be assigned"
|
47
|
+
|
48
|
+
values_match?(false, assign_value.nil?)
|
49
|
+
end
|
50
|
+
|
51
|
+
def check_assign_with
|
52
|
+
@description = "assign @#{assign_key} with #{assign_with.inspect}"
|
53
|
+
@failure_message = "expected @#{assign_key} to be assigned with #{assign_with.inspect} but was assigned with #{assign_value.inspect}"
|
54
|
+
@failure_message_when_negated = "expected @#{assign_key} to not be assigned with #{assign_with.inspect}"
|
55
|
+
|
56
|
+
values_match?(assign_with, assign_value)
|
57
|
+
end
|
58
|
+
|
59
|
+
def check_assign_with_a
|
60
|
+
@description = "assign @#{assign_key} with an instance of #{assign_with_a.name}"
|
61
|
+
@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
|
+
@failure_message_when_negated = "expected @#{assign_key} to not be assigned with an instance of #{assign_with_a.name}"
|
63
|
+
|
64
|
+
has_ancestor?(assign_value, assign_with_a)
|
65
|
+
end
|
66
|
+
|
67
|
+
def check_assign_with_a_new
|
68
|
+
@description = "assign @#{assign_key} with a new instance of #{assign_with_a_new.name}"
|
69
|
+
@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
|
+
@failure_message_when_negated = "expected @#{assign_key} to not be assigned with a new instance of #{assign_with_a_new.name}"
|
71
|
+
|
72
|
+
has_ancestor?(assign_value, assign_with_a_new) && values_match?(false, assign_value.persisted?)
|
73
|
+
end
|
74
|
+
|
75
|
+
def assign_value
|
76
|
+
controller.view_assigns[assign_key.to_s]
|
77
|
+
end
|
78
|
+
|
79
|
+
def multiple_assertions?
|
80
|
+
[@assign_with, @assign_with_a, @assign_with_a_new].compact.size > 1
|
81
|
+
end
|
82
|
+
|
83
|
+
def has_ancestor?(object, klass)
|
84
|
+
object.class.ancestors.any? {|ancestor| values_match?(klass, ancestor) }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def assign(assign_key)
|
89
|
+
AssignMatcher.new(assign_key)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Warp
|
2
|
+
module ControllerMatchers
|
3
|
+
class SetFlashMatcher
|
4
|
+
include RSpec::Matchers::Composable
|
5
|
+
|
6
|
+
attr_reader :flash_key, :expected_flash_value
|
7
|
+
attr_reader :controller, :failure_message, :failure_message_when_negated, :description
|
8
|
+
|
9
|
+
def initialize(flash_key)
|
10
|
+
@flash_key = flash_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def to(expected_flash_value)
|
14
|
+
@expected_flash_value = expected_flash_value
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def matches?(controller)
|
19
|
+
@controller = controller
|
20
|
+
|
21
|
+
if expected_flash_value
|
22
|
+
@description = "set flash[:#{flash_key}] to #{expected_flash_value.inspect}"
|
23
|
+
@failure_message = "expected flash[:#{flash_key}] to be set to #{expected_flash_value.inspect}"
|
24
|
+
@failure_message_when_negated = "expected flash[:#{flash_key}] to not be set to #{expected_flash_value.inspect}"
|
25
|
+
values_match?(expected_flash_value, flash_value)
|
26
|
+
else
|
27
|
+
@description = "set flash[:#{flash_key}]"
|
28
|
+
@failure_message = "expected flash[:#{flash_key}] to be set"
|
29
|
+
@failure_message_when_negated = "expected flash[:#{flash_key}] to not be set"
|
30
|
+
values_match?(false, flash_value.nil?)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def flash_value
|
37
|
+
flash[flash_key]
|
38
|
+
end
|
39
|
+
|
40
|
+
def flash
|
41
|
+
controller.flash
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def set_flash(flash_key)
|
46
|
+
SetFlashMatcher.new(flash_key)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/warp/version.rb
ADDED
data/lib/warp.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
|
3
|
+
if ENV["TRAVIS_CI"]
|
4
|
+
Bundler.require
|
5
|
+
else
|
6
|
+
Bundler.require(:default, :tools)
|
7
|
+
end
|
8
|
+
|
9
|
+
require "active_support/all"
|
10
|
+
require "action_controller"
|
11
|
+
|
12
|
+
require "warp"
|
13
|
+
|
14
|
+
Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f }
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.order = 'random'
|
18
|
+
|
19
|
+
config.extend ControllerHelpers
|
20
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module ControllerHelpers
|
2
|
+
def build_controller
|
3
|
+
let(:controller_class) do
|
4
|
+
Class.new(ActionController::Metal).tap do |klass|
|
5
|
+
klass.instance_eval do
|
6
|
+
def helper_method(*_); end
|
7
|
+
end
|
8
|
+
|
9
|
+
klass.send :include, ActionController::Rendering
|
10
|
+
klass.send :include, ActionController::Flash
|
11
|
+
klass.send :include, AbstractController::Rendering
|
12
|
+
klass.send :include, ActionController::Rendering
|
13
|
+
|
14
|
+
klass.send :cattr_accessor, :spec
|
15
|
+
klass.spec = self
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:request) do
|
20
|
+
ActionDispatch::TestRequest.new(ActionDispatch::TestRequest::DEFAULT_ENV.dup).tap do |request|
|
21
|
+
request.class_eval do
|
22
|
+
def flash
|
23
|
+
@env[ActionDispatch::Flash::KEY] ||= ActionDispatch::Flash::FlashHash.new
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:controller) do
|
30
|
+
controller_class.new.tap do |controller|
|
31
|
+
controller.instance_variable_set(:@_request, request)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def controller_action(&blk)
|
37
|
+
before do
|
38
|
+
controller_class.send :define_method, :index do
|
39
|
+
instance_eval(&blk)
|
40
|
+
render text: ""
|
41
|
+
end
|
42
|
+
|
43
|
+
controller.dispatch(:index, request)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
RSpec::Matchers.define :match do |value|
|
2
|
+
match do |matcher|
|
3
|
+
@matcher = matcher
|
4
|
+
matcher.matches?(value)
|
5
|
+
end
|
6
|
+
|
7
|
+
description do
|
8
|
+
"match #{value}"
|
9
|
+
end
|
10
|
+
|
11
|
+
failure_message do
|
12
|
+
"expect #{@matcher} to match #{value} but did not"
|
13
|
+
end
|
14
|
+
|
15
|
+
failure_message_when_negated do
|
16
|
+
"expect #{@matcher} to not match #{value} but did"
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,213 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Warp::ControllerMatchers::AssignMatcher do
|
4
|
+
build_controller
|
5
|
+
|
6
|
+
subject { assign(:assign) }
|
7
|
+
|
8
|
+
describe "#description" do
|
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
|
27
|
+
|
28
|
+
context "when not assigned" do
|
29
|
+
controller_action do
|
30
|
+
# no assign
|
31
|
+
end
|
32
|
+
|
33
|
+
specify { expect(subject).to_not match(controller) }
|
34
|
+
|
35
|
+
describe "#failure_message" do
|
36
|
+
subject { super().matches?(controller); super().failure_message }
|
37
|
+
|
38
|
+
specify { expect(subject).to eq "expected @assign to be assigned" }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#with" do
|
43
|
+
controller_action do
|
44
|
+
@assign = spec.actual_assign_value
|
45
|
+
end
|
46
|
+
|
47
|
+
let(:actual_assign_value) { "foobar" }
|
48
|
+
let(:expected_assign_value) { "foobar" }
|
49
|
+
|
50
|
+
subject { super().with(expected_assign_value) }
|
51
|
+
|
52
|
+
describe "#description" do
|
53
|
+
subject { super().matches?(controller); super().description }
|
54
|
+
|
55
|
+
specify { expect(subject).to eq "assign @assign with #{expected_assign_value.inspect}" }
|
56
|
+
end
|
57
|
+
|
58
|
+
context "with the right value" do
|
59
|
+
specify { expect(subject).to match(controller) }
|
60
|
+
|
61
|
+
describe "#failure_message_when_negated" do
|
62
|
+
subject { super().matches?(controller); super().failure_message_when_negated }
|
63
|
+
|
64
|
+
specify { expect(subject).to eq "expected @assign to not be assigned with #{expected_assign_value.inspect}" }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "with the wrong value" do
|
69
|
+
let(:expected_assign_value) { "foobaz" }
|
70
|
+
|
71
|
+
specify { expect(subject).to_not match(controller) }
|
72
|
+
|
73
|
+
describe "#failure_message" do
|
74
|
+
subject { super().matches?(controller); super().failure_message }
|
75
|
+
|
76
|
+
specify { expect(subject).to eq "expected @assign to be assigned with #{expected_assign_value.inspect} but was assigned with #{actual_assign_value.inspect}" }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#with_a" do
|
82
|
+
controller_action do
|
83
|
+
@assign = spec.actual_assign_class.new
|
84
|
+
end
|
85
|
+
|
86
|
+
let(:actual_assign_class) { Class.new.tap {|klass| allow(klass).to receive(:name) { "FooClass" } } }
|
87
|
+
let(:expected_assign_class) { actual_assign_class }
|
88
|
+
|
89
|
+
subject { assign(:assign).with_a(expected_assign_class) }
|
90
|
+
|
91
|
+
describe "#description" do
|
92
|
+
subject { super().matches?(controller); super().description }
|
93
|
+
|
94
|
+
specify { expect(subject).to eq "assign @assign with an instance of #{expected_assign_class.name}" }
|
95
|
+
end
|
96
|
+
|
97
|
+
context "with the right class" do
|
98
|
+
specify { expect(subject).to match(controller) }
|
99
|
+
|
100
|
+
describe "#failure_message_when_negated" do
|
101
|
+
subject { super().matches?(controller); super().failure_message_when_negated }
|
102
|
+
|
103
|
+
specify { expect(subject).to eq "expected @assign to not be assigned with an instance of #{expected_assign_class.name}" }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "with the wrong class" do
|
108
|
+
let(:expected_assign_class) { Class.new.tap {|klass| allow(klass).to receive(:name) { "BarClass" } } }
|
109
|
+
|
110
|
+
specify { expect(subject).to_not match(controller) }
|
111
|
+
|
112
|
+
describe "#failure_message" do
|
113
|
+
subject { super().matches?(controller); super().failure_message }
|
114
|
+
|
115
|
+
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}"
|
116
|
+
}
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "#with_a_new" do
|
122
|
+
controller_action do
|
123
|
+
@assign = spec.actual_assign_class.new
|
124
|
+
end
|
125
|
+
|
126
|
+
let(:actual_persisted?) { false }
|
127
|
+
let(:actual_assign_class) do
|
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
|
133
|
+
|
134
|
+
let(:expected_assign_class) { actual_assign_class }
|
135
|
+
|
136
|
+
subject { assign(:assign).with_a_new(expected_assign_class) }
|
137
|
+
|
138
|
+
describe "#description" do
|
139
|
+
subject { super().matches?(controller); super().description }
|
140
|
+
|
141
|
+
specify { expect(subject).to eq "assign @assign with a new instance of #{expected_assign_class.name}" }
|
142
|
+
end
|
143
|
+
|
144
|
+
context "with a new object" do
|
145
|
+
let(:actual_persisted?) { false }
|
146
|
+
|
147
|
+
context "with the right class" do
|
148
|
+
specify { expect(subject).to match(controller) }
|
149
|
+
|
150
|
+
describe "#failure_message_when_negated" do
|
151
|
+
subject { super().matches?(controller); super().failure_message_when_negated }
|
152
|
+
|
153
|
+
specify { expect(subject).to eq "expected @assign to not be assigned with a new instance of #{expected_assign_class.name}" }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "with a descendant class" do
|
158
|
+
let(:actual_assign_class) do
|
159
|
+
Class.new(super())
|
160
|
+
end
|
161
|
+
|
162
|
+
specify { expect(subject).to match(controller) }
|
163
|
+
|
164
|
+
describe "#failure_message_when_negated" do
|
165
|
+
subject { super().matches?(controller); super().failure_message_when_negated }
|
166
|
+
|
167
|
+
specify { expect(subject).to eq "expected @assign to not be assigned with a new instance of #{expected_assign_class.name}" }
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context "with the wrong class" do
|
172
|
+
let(:expected_assign_class) { Class.new.tap {|klass| allow(klass).to receive(:name) { "BarClass" } } }
|
173
|
+
|
174
|
+
specify { expect(subject).to_not match(controller) }
|
175
|
+
|
176
|
+
describe "#failure_message" do
|
177
|
+
subject { super().matches?(controller); super().failure_message }
|
178
|
+
|
179
|
+
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}"
|
180
|
+
}
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context "with a persisted object" do
|
186
|
+
let(:actual_persisted?) { true }
|
187
|
+
|
188
|
+
context "with the right class" do
|
189
|
+
specify { expect(subject).to_not match(controller) }
|
190
|
+
|
191
|
+
describe "#failure_message" do
|
192
|
+
subject { super().matches?(controller); super().failure_message }
|
193
|
+
|
194
|
+
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}"
|
195
|
+
}
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
context "with the wrong class" do
|
200
|
+
let(:expected_assign_class) { Class.new.tap {|klass| allow(klass).to receive(:name) { "BarClass" } } }
|
201
|
+
|
202
|
+
specify { expect(subject).to_not match(controller) }
|
203
|
+
|
204
|
+
describe "#failure_message" do
|
205
|
+
subject { super().matches?(controller); super().failure_message }
|
206
|
+
|
207
|
+
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}"
|
208
|
+
}
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Warp::ControllerMatchers::SetFlashMatcher do
|
4
|
+
build_controller
|
5
|
+
|
6
|
+
let(:flash_key) { [:notice, :error].sample }
|
7
|
+
|
8
|
+
subject { set_flash(flash_key) }
|
9
|
+
|
10
|
+
describe "#description" do
|
11
|
+
subject { super().matches?(controller); super().description }
|
12
|
+
|
13
|
+
specify { expect(subject).to eq "set flash[:#{flash_key}]" }
|
14
|
+
end
|
15
|
+
|
16
|
+
context "with a flash set" do
|
17
|
+
let(:actual_flash_value) { Object.new }
|
18
|
+
|
19
|
+
controller_action do
|
20
|
+
flash[spec.flash_key] = spec.actual_flash_value
|
21
|
+
end
|
22
|
+
|
23
|
+
specify { expect(subject).to match(controller) }
|
24
|
+
|
25
|
+
describe "#failure_message_when_negated" do
|
26
|
+
subject { super().matches?(controller); super().failure_message_when_negated }
|
27
|
+
|
28
|
+
specify { expect(subject).to eq "expected flash[:#{flash_key}] to not be set" }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with no flash set" do
|
33
|
+
specify { expect(subject).to_not match(controller) }
|
34
|
+
|
35
|
+
describe "#failure_message" do
|
36
|
+
subject { super().matches?(controller); super().failure_message }
|
37
|
+
|
38
|
+
specify { expect(subject).to eq "expected flash[:#{flash_key}] to be set" }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#to" do
|
43
|
+
let(:expected_flash_value) { Object.new }
|
44
|
+
|
45
|
+
subject { set_flash(flash_key).to(expected_flash_value) }
|
46
|
+
|
47
|
+
describe "#description" do
|
48
|
+
subject { super().matches?(controller); super().description }
|
49
|
+
|
50
|
+
specify { expect(subject).to eq "set flash[:#{flash_key}] to #{expected_flash_value.inspect}" }
|
51
|
+
end
|
52
|
+
|
53
|
+
context "with expexted flash value" do
|
54
|
+
let(:actual_flash_value) { expected_flash_value }
|
55
|
+
|
56
|
+
controller_action do
|
57
|
+
flash[spec.flash_key] = spec.actual_flash_value
|
58
|
+
end
|
59
|
+
|
60
|
+
specify { expect(subject).to match(controller) }
|
61
|
+
|
62
|
+
describe "#failure_message_when_negated" do
|
63
|
+
subject { super().matches?(controller); super().failure_message_when_negated }
|
64
|
+
|
65
|
+
specify { expect(subject).to eq "expected flash[:#{flash_key}] to not be set to #{expected_flash_value.inspect}" }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "with unexpexted flash value" do
|
70
|
+
let(:actual_flash_value) { Object.new }
|
71
|
+
|
72
|
+
specify { expect(subject).to_not match(controller) }
|
73
|
+
|
74
|
+
describe "#failure_message" do
|
75
|
+
subject { super().matches?(controller); super().failure_message }
|
76
|
+
|
77
|
+
specify { expect(subject).to eq "expected flash[:#{flash_key}] to be set to #{expected_flash_value.inspect}" }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/warp.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'warp/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "warp"
|
8
|
+
spec.version = Warp::VERSION
|
9
|
+
spec.authors = ["Thomas Drake-Brockman"]
|
10
|
+
spec.email = ["thom@sfedb.com"]
|
11
|
+
spec.description = %q{Rails matchers for your RSpec specs.}
|
12
|
+
spec.summary = %q{Warp provides matchers for testing your Rails application with RSpec.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(spec)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# spec.add_runtime_dependency "rspec", ">= 2.14.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5.1"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "fuubar"
|
26
|
+
|
27
|
+
spec.add_development_dependency "activesupport"
|
28
|
+
spec.add_development_dependency "actionpack"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: warp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thomas Drake-Brockman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.5.1
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.5.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fuubar
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: actionpack
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Rails matchers for your RSpec specs.
|
84
|
+
email:
|
85
|
+
- thom@sfedb.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".ruby-gemset"
|
92
|
+
- ".ruby-version"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- Guardfile
|
96
|
+
- LICENSE
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- gemfiles/rails-3.2
|
100
|
+
- gemfiles/rails-4.0
|
101
|
+
- gemfiles/rails-4.1
|
102
|
+
- lib/warp.rb
|
103
|
+
- lib/warp/controller_matchers.rb
|
104
|
+
- lib/warp/controller_matchers/assign_matcher.rb
|
105
|
+
- lib/warp/controller_matchers/set_flash_matcher.rb
|
106
|
+
- lib/warp/version.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
- spec/support/controller_helpers.rb
|
109
|
+
- spec/support/match_helpers.rb
|
110
|
+
- spec/warp/controller_matchers/assign_matcher_spec.rb
|
111
|
+
- spec/warp/controller_matchers/set_flash_matcher_spec.rb
|
112
|
+
- warp.gemspec
|
113
|
+
homepage: ''
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
metadata: {}
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 2.2.0
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: Warp provides matchers for testing your Rails application with RSpec.
|
137
|
+
test_files:
|
138
|
+
- spec/spec_helper.rb
|
139
|
+
- spec/support/controller_helpers.rb
|
140
|
+
- spec/support/match_helpers.rb
|
141
|
+
- spec/warp/controller_matchers/assign_matcher_spec.rb
|
142
|
+
- spec/warp/controller_matchers/set_flash_matcher_spec.rb
|