rspec-collection_matchers 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Changelog.md +8 -0
- data/Gemfile +22 -1
- data/lib/rspec/collection_matchers.rb +1 -0
- data/lib/rspec/collection_matchers/have.rb +10 -0
- data/lib/rspec/collection_matchers/rails_extensions.rb +26 -0
- data/lib/rspec/collection_matchers/version.rb +1 -1
- data/rspec-collection_matchers.gemspec +2 -1
- data/spec/rspec/collection_matchers/have_spec.rb +2 -2
- data/spec/rspec/collection_matchers/rails_extensions_spec.rb +99 -0
- data/spec/spec_helper.rb +15 -1
- metadata +32 -27
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 86054489823ad2296c0bffaea74803acb7488d8a
|
4
|
+
data.tar.gz: b5d8d76f482bcbcd7d8c290bdd656379d3efd0dc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ac223d5be9e8bcb6bd1a70dc7e09934428ecee6efe7d2e2d3d0f81ed6a25ea7237cfe8fecbc8cdd67ae69aa84cbb044e87d114ee051de4c54f29d5abf977cef1
|
7
|
+
data.tar.gz: a73e52b3b592bb067306d666522352d8c61fdaf7051bbcd17f475b0d1a4f1d17154e2f965d3a93f9db8ece4fce2e176806d3e8836354e0306cebef7f7944a2d5
|
data/Changelog.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
### 0.0.4 / 2014-04-24
|
2
|
+
|
3
|
+
[full changelog](http://github.com/rspec/rspec-collection_matchers/compare/v0.0.3...v0.0.4)
|
4
|
+
|
5
|
+
Enhancements:
|
6
|
+
|
7
|
+
* Add Rails extension `have(n).errors_on(:whatever)` (Bradley Schaefer)
|
8
|
+
|
1
9
|
### 0.0.3 / 2014-02-16
|
2
10
|
|
3
11
|
[full changelog](http://github.com/rspec/rspec-collection_matchers/compare/v0.0.2...v0.0.3)
|
data/Gemfile
CHANGED
@@ -12,13 +12,34 @@ gemspec
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
# only the master
|
15
|
+
# only the master branch is supported on rspec-support
|
16
16
|
gem "rspec-support", :git => "git://github.com/rspec/rspec-support.git"
|
17
17
|
|
18
18
|
gem "cucumber", "~> 1.1.9"
|
19
19
|
gem "aruba", "~> 0.5"
|
20
20
|
gem "rake", "~> 10.0.0"
|
21
21
|
|
22
|
+
version_file = File.expand_path("../.rails-version", __FILE__)
|
23
|
+
rails_gem_args = case version = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp)
|
24
|
+
when /master/
|
25
|
+
{ :git => "git://github.com/rails/rails.git" }
|
26
|
+
when /stable$/
|
27
|
+
{ :git => "git://github.com/rails/rails.git", :branch => version }
|
28
|
+
when nil, false, ""
|
29
|
+
if RUBY_VERSION < '1.9.3'
|
30
|
+
# Rails 4+ requires 1.9.3+, so on earlier versions default to the last 3.x release.
|
31
|
+
"3.2.17"
|
32
|
+
else
|
33
|
+
"4.0.4"
|
34
|
+
end
|
35
|
+
else
|
36
|
+
version
|
37
|
+
end
|
38
|
+
|
39
|
+
gem "activesupport", *rails_gem_args
|
40
|
+
gem "activemodel", *rails_gem_args
|
41
|
+
|
42
|
+
|
22
43
|
platform :rbx do
|
23
44
|
gem 'rubysl'
|
24
45
|
end
|
@@ -70,6 +70,7 @@ module RSpec
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def failure_message
|
73
|
+
return errors_on_message(:expected, ", got #{@actual}") if is_errors_on?
|
73
74
|
"expected #{relative_expectation} #{@collection_name}, got #{@actual}"
|
74
75
|
end
|
75
76
|
alias failure_message_for_should failure_message
|
@@ -98,6 +99,7 @@ EOF
|
|
98
99
|
alias failure_message_for_should_not failure_message_when_negated
|
99
100
|
|
100
101
|
def description
|
102
|
+
return errors_on_message(:have) if is_errors_on?
|
101
103
|
"have #{relative_expectation} #{@collection_name}"
|
102
104
|
end
|
103
105
|
|
@@ -124,6 +126,14 @@ EOF
|
|
124
126
|
def enumerator_class
|
125
127
|
RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator
|
126
128
|
end
|
129
|
+
|
130
|
+
def is_errors_on?
|
131
|
+
[:errors_on, :error_on].include? @collection_name
|
132
|
+
end
|
133
|
+
|
134
|
+
def errors_on_message(prefix, suffix = nil)
|
135
|
+
"#{prefix} #{relative_expectation} #{@collection_name.to_s.gsub('_', ' ')} :#{@args[0]}#{suffix}"
|
136
|
+
end
|
127
137
|
end
|
128
138
|
|
129
139
|
module Syntax
|
@@ -0,0 +1,26 @@
|
|
1
|
+
if defined?(::ActiveModel)
|
2
|
+
module ::ActiveModel::Validations
|
3
|
+
# Extension to enhance `to have` on AR Model instances. Calls
|
4
|
+
# model.valid? in order to prepare the object's errors object. Accepts
|
5
|
+
# a :context option to specify the validation context.
|
6
|
+
#
|
7
|
+
# You can also use this to specify the content of the error messages.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
#
|
11
|
+
# expect(model).to have(:no).errors_on(:attribute)
|
12
|
+
# expect(model).to have(1).error_on(:attribute)
|
13
|
+
# expect(model).to have(n).errors_on(:attribute)
|
14
|
+
# expect(model).to have(n).errors_on(:attribute, :context => :create)
|
15
|
+
#
|
16
|
+
# expect(model.errors_on(:attribute)).to include("can't be blank")
|
17
|
+
def errors_on(attribute, options = {})
|
18
|
+
valid_args = [options[:context]].compact
|
19
|
+
self.valid?(*valid_args)
|
20
|
+
|
21
|
+
[self.errors[attribute]].flatten.compact
|
22
|
+
end
|
23
|
+
|
24
|
+
alias :error_on :errors_on
|
25
|
+
end
|
26
|
+
end
|
@@ -20,5 +20,6 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_runtime_dependency "rspec-expectations", ">= 2.99.0.beta1"
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler",
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "activemodel", ">= 3.0"
|
24
25
|
end
|
@@ -338,14 +338,14 @@ EOF
|
|
338
338
|
describe "have(n).items(args, block)" do
|
339
339
|
it "passes args to target" do
|
340
340
|
target = double("target")
|
341
|
-
target.
|
341
|
+
expect(target).to receive(:items).with("arg1","arg2").and_return([1,2,3])
|
342
342
|
expect(target).to have(3).items("arg1","arg2")
|
343
343
|
end
|
344
344
|
|
345
345
|
it "passes block to target" do
|
346
346
|
target = double("target")
|
347
347
|
block = Proc.new { 5 }
|
348
|
-
target.
|
348
|
+
expect(target).to receive(:items).with("arg1","arg2", block).and_return([1,2,3])
|
349
349
|
expect(target).to have(3).items("arg1","arg2", block)
|
350
350
|
end
|
351
351
|
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require 'active_model'
|
3
|
+
|
4
|
+
module RSpec::CollectionMatchers
|
5
|
+
describe "Have extensions for rails" do
|
6
|
+
describe "error_on" do
|
7
|
+
it "provides a description including the name of what the error is on" do
|
8
|
+
expect(have(1).error_on(:whatever).description).to eq "have 1 error on :whatever"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "provides a failure message including the number actually given" do
|
12
|
+
expect {
|
13
|
+
expect([]).to have(1).error_on(:whatever)
|
14
|
+
}.to raise_error("expected 1 error on :whatever, got 0")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "errors_on" do
|
19
|
+
it "provides a description including the name of what the error is on" do
|
20
|
+
expect(have(2).errors_on(:whatever).description).to eq "have 2 errors on :whatever"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "provides a failure message including the number actually given" do
|
24
|
+
expect {
|
25
|
+
expect([1]).to have(3).errors_on(:whatever)
|
26
|
+
}.to raise_error("expected 3 errors on :whatever, got 1")
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:klass) do
|
30
|
+
Class.new do
|
31
|
+
include ActiveModel::Validations
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "calls valid?" do
|
36
|
+
model = klass.new
|
37
|
+
expect(model).to receive(:valid?)
|
38
|
+
model.errors_on(:foo)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns the errors on that attribute" do
|
42
|
+
model = klass.new
|
43
|
+
allow(model).to receive(:errors) do
|
44
|
+
{ :foo => ['a', 'b'] }
|
45
|
+
end
|
46
|
+
expect(model.errors_on(:foo)).to eq(['a','b'])
|
47
|
+
end
|
48
|
+
|
49
|
+
context "ActiveModel class that takes no arguments to valid?" do
|
50
|
+
let(:klass) {
|
51
|
+
Class.new do
|
52
|
+
include ActiveModel::Validations
|
53
|
+
|
54
|
+
def self.name
|
55
|
+
"ActiveModelValidationsFake"
|
56
|
+
end
|
57
|
+
|
58
|
+
def valid?
|
59
|
+
super
|
60
|
+
end
|
61
|
+
|
62
|
+
attr_accessor :name
|
63
|
+
validates_presence_of :name
|
64
|
+
end
|
65
|
+
}
|
66
|
+
|
67
|
+
context "with nil name" do
|
68
|
+
it "has one error" do
|
69
|
+
object = klass.new
|
70
|
+
object.name = ""
|
71
|
+
|
72
|
+
expect(object).to have(1).error_on(:name)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "with non-blank name" do
|
77
|
+
it "has no error" do
|
78
|
+
object = klass.new
|
79
|
+
object.name = "Ywen"
|
80
|
+
|
81
|
+
expect(object).to have(:no).error_on(:name)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "have something other than error_on or errors_on" do
|
88
|
+
it "has a standard rspec failure message" do
|
89
|
+
expect {
|
90
|
+
expect([1,2,3]).to have(2).elements
|
91
|
+
}.to raise_error("expected 2 elements, got 3")
|
92
|
+
end
|
93
|
+
|
94
|
+
it "has a standard rspec description" do
|
95
|
+
expect(have(2).elements.description).to eq "have 2 elements"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,27 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
|
3
|
+
# to avoid deprecation warning:
|
4
|
+
# [deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
|
5
|
+
I18n.enforce_available_locales = false
|
6
|
+
|
1
7
|
require 'rspec/collection_matchers'
|
2
8
|
|
3
9
|
Dir['./spec/support/**/*'].each {|f| require f}
|
4
10
|
|
5
11
|
RSpec.configure do |config|
|
6
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true if RSpec::Core::Version::STRING < "3.0"
|
7
13
|
config.run_all_when_everything_filtered = true
|
8
14
|
config.filter_run :focus
|
9
15
|
|
10
16
|
config.order = 'random'
|
17
|
+
|
18
|
+
config.expect_with :rspec do |rspec|
|
19
|
+
rspec.syntax = :expect
|
20
|
+
end
|
21
|
+
|
22
|
+
config.mock_with :rspec do |rspec|
|
23
|
+
rspec.syntax = :expect
|
24
|
+
end
|
11
25
|
end
|
12
26
|
|
13
27
|
shared_context "with #should enabled", :uses_should do
|
metadata
CHANGED
@@ -1,48 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-collection_matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Hugo Baraúna
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-04-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec-expectations
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 2.99.0.beta1
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 2.99.0.beta1
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: bundler
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '1.3'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activemodel
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
46
55
|
description: Collection cardinality matchers, extracted from rspec-expectations
|
47
56
|
email:
|
48
57
|
- hugo.barauna@plataformatec.com.br
|
@@ -50,9 +59,9 @@ executables: []
|
|
50
59
|
extensions: []
|
51
60
|
extra_rdoc_files: []
|
52
61
|
files:
|
53
|
-
- .gitignore
|
54
|
-
- .rspec
|
55
|
-
- .travis.yml
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
56
65
|
- Changelog.md
|
57
66
|
- Gemfile
|
58
67
|
- LICENSE.txt
|
@@ -63,10 +72,12 @@ files:
|
|
63
72
|
- lib/rspec/collection_matchers.rb
|
64
73
|
- lib/rspec/collection_matchers/have.rb
|
65
74
|
- lib/rspec/collection_matchers/matchers.rb
|
75
|
+
- lib/rspec/collection_matchers/rails_extensions.rb
|
66
76
|
- lib/rspec/collection_matchers/version.rb
|
67
77
|
- rspec-collection_matchers.gemspec
|
68
78
|
- script/test_all
|
69
79
|
- spec/rspec/collection_matchers/have_spec.rb
|
80
|
+
- spec/rspec/collection_matchers/rails_extensions_spec.rb
|
70
81
|
- spec/spec_helper.rb
|
71
82
|
- spec/support/classes.rb
|
72
83
|
- spec/support/matchers.rb
|
@@ -74,38 +85,32 @@ files:
|
|
74
85
|
homepage: https://github.com/rspec/rspec-collection_matchers
|
75
86
|
licenses:
|
76
87
|
- MIT
|
88
|
+
metadata: {}
|
77
89
|
post_install_message:
|
78
90
|
rdoc_options: []
|
79
91
|
require_paths:
|
80
92
|
- lib
|
81
93
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
94
|
requirements:
|
84
|
-
- -
|
95
|
+
- - ">="
|
85
96
|
- !ruby/object:Gem::Version
|
86
97
|
version: '0'
|
87
|
-
segments:
|
88
|
-
- 0
|
89
|
-
hash: -3346654767301501509
|
90
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
-
none: false
|
92
99
|
requirements:
|
93
|
-
- -
|
100
|
+
- - ">="
|
94
101
|
- !ruby/object:Gem::Version
|
95
102
|
version: '0'
|
96
|
-
segments:
|
97
|
-
- 0
|
98
|
-
hash: -3346654767301501509
|
99
103
|
requirements: []
|
100
104
|
rubyforge_project:
|
101
|
-
rubygems_version:
|
105
|
+
rubygems_version: 2.2.0
|
102
106
|
signing_key:
|
103
|
-
specification_version:
|
104
|
-
summary: rspec-collection_matchers-0.0.
|
107
|
+
specification_version: 4
|
108
|
+
summary: rspec-collection_matchers-0.0.4
|
105
109
|
test_files:
|
106
110
|
- features/have.feature
|
107
111
|
- features/support/env.rb
|
108
112
|
- spec/rspec/collection_matchers/have_spec.rb
|
113
|
+
- spec/rspec/collection_matchers/rails_extensions_spec.rb
|
109
114
|
- spec/spec_helper.rb
|
110
115
|
- spec/support/classes.rb
|
111
116
|
- spec/support/matchers.rb
|