rspec-collection_matchers 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,16 +2,15 @@ language: ruby
2
2
  script: "script/test_all"
3
3
  bundler_args: "--standalone --binstubs --without documentation"
4
4
  rvm:
5
- - 1.8.7
6
- - 1.9.2
5
+ - 2.1.0
6
+ - 2.0.0
7
7
  - 1.9.3
8
+ - 1.9.2
9
+ - 1.8.7
8
10
  - ree
9
- - jruby-18mode
10
11
  - jruby-19mode
11
- - rbx-18mode
12
- - rbx-19mode
13
- - 2.0.0
14
- matrix:
15
- allow_failures:
16
- - rvm: rbx-19mode
17
- - rvm: rbx-18mode
12
+ - jruby-18mode
13
+ - rbx
14
+ env:
15
+ - BRANCH=master
16
+ - BRANCH=2-99-maintenance
@@ -0,0 +1,12 @@
1
+ ### 0.0.3 / 2014-02-16
2
+
3
+ [full changelog](http://github.com/rspec/rspec-collection_matchers/compare/v0.0.2...v0.0.3)
4
+
5
+ Enhancements:
6
+
7
+ * Update to latest RSpec 3 matcher API. (Myron Marston)
8
+
9
+ Bug Fixes:
10
+
11
+ * Raise an error when you attempt to use matcher against an `Integer`
12
+ which previously would have incorrectly used a `#size` of 8. (Kassio Borges)
data/Gemfile CHANGED
@@ -7,12 +7,20 @@ gemspec
7
7
  if File.exist?(library_path)
8
8
  gem lib, :path => library_path
9
9
  else
10
- gem lib, :git => "git://github.com/rspec/#{lib}.git", :branch => "2-99-maintenance"
10
+ gem lib, :git => "git://github.com/rspec/#{lib}.git",
11
+ :branch => ENV.fetch('BRANCH',"master")
11
12
  end
12
13
  end
13
14
 
15
+ # only the master branche is supported on rspec-support
16
+ gem "rspec-support", :git => "git://github.com/rspec/rspec-support.git"
17
+
14
18
  gem "cucumber", "~> 1.1.9"
15
19
  gem "aruba", "~> 0.5"
16
20
  gem "rake", "~> 10.0.0"
17
21
 
22
+ platform :rbx do
23
+ gem 'rubysl'
24
+ end
25
+
18
26
  eval File.read('Gemfile-custom') if File.exist?('Gemfile-custom')
@@ -2,6 +2,7 @@ module RSpec
2
2
  module CollectionMatchers
3
3
  class Have
4
4
  QUERY_METHODS = [:size, :length, :count].freeze
5
+ IGNORED_CLASSES = [Integer].freeze
5
6
 
6
7
  def initialize(expected, relativity=:exactly)
7
8
  @expected = case expected
@@ -33,7 +34,7 @@ module RSpec
33
34
  raise not_a_collection if @actual.nil?
34
35
  else
35
36
  query_method = determine_query_method(collection)
36
- raise not_a_collection unless query_method
37
+ raise not_a_collection if !query_method || is_ignored_class?(collection)
37
38
  @actual = collection.__send__(query_method)
38
39
  end
39
40
  case @relativity
@@ -60,35 +61,41 @@ module RSpec
60
61
  QUERY_METHODS.detect {|m| collection.respond_to?(m)}
61
62
  end
62
63
 
64
+ def is_ignored_class?(collection)
65
+ IGNORED_CLASSES.any? {|klass| klass === collection}
66
+ end
67
+
63
68
  def not_a_collection
64
69
  "expected #{@collection_name} to be a collection but it does not respond to #length, #size or #count"
65
70
  end
66
71
 
67
- def failure_message_for_should
72
+ def failure_message
68
73
  "expected #{relative_expectation} #{@collection_name}, got #{@actual}"
69
74
  end
75
+ alias failure_message_for_should failure_message
70
76
 
71
- def failure_message_for_should_not
77
+ def failure_message_when_negated
72
78
  if @relativity == :exactly
73
79
  return "expected target not to have #{@expected} #{@collection_name}, got #{@actual}"
74
80
  elsif @relativity == :at_most
75
81
  return <<-EOF
76
82
  Isn't life confusing enough?
77
83
  Instead of having to figure out the meaning of this:
78
- #{Expectations::Syntax.negative_expression("actual", "have_at_most(#{@expected}).#{@collection_name}")}
84
+ #{Syntax.negative_expression("actual", "have_at_most(#{@expected}).#{@collection_name}")}
79
85
  We recommend that you use this instead:
80
- #{Expectations::Syntax.positive_expression("actual", "have_at_least(#{@expected + 1}).#{@collection_name}")}
86
+ #{Syntax.positive_expression("actual", "have_at_least(#{@expected + 1}).#{@collection_name}")}
81
87
  EOF
82
88
  elsif @relativity == :at_least
83
89
  return <<-EOF
84
90
  Isn't life confusing enough?
85
91
  Instead of having to figure out the meaning of this:
86
- #{Expectations::Syntax.negative_expression("actual", "have_at_least(#{@expected}).#{@collection_name}")}
92
+ #{Syntax.negative_expression("actual", "have_at_least(#{@expected}).#{@collection_name}")}
87
93
  We recommend that you use this instead:
88
- #{Expectations::Syntax.positive_expression("actual", "have_at_most(#{@expected - 1}).#{@collection_name}")}
94
+ #{Syntax.positive_expression("actual", "have_at_most(#{@expected - 1}).#{@collection_name}")}
89
95
  EOF
90
96
  end
91
97
  end
98
+ alias failure_message_for_should_not failure_message_when_negated
92
99
 
93
100
  def description
94
101
  "have #{relative_expectation} #{@collection_name}"
@@ -118,5 +125,53 @@ EOF
118
125
  RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator
119
126
  end
120
127
  end
128
+
129
+ module Syntax
130
+ # @api private
131
+ # Generates a positive expectation expression.
132
+ def self.positive_expression(target_expression, matcher_expression)
133
+ expression_generator.positive_expression(target_expression, matcher_expression)
134
+ end
135
+
136
+ # @api private
137
+ # Generates a negative expectation expression.
138
+ def self.negative_expression(target_expression, matcher_expression)
139
+ expression_generator.negative_expression(target_expression, matcher_expression)
140
+ end
141
+
142
+ # @api private
143
+ # Selects which expression generator to use based on the configured syntax.
144
+ def self.expression_generator
145
+ if RSpec::Expectations::Syntax.expect_enabled?
146
+ ExpectExpressionGenerator
147
+ else
148
+ ShouldExpressionGenerator
149
+ end
150
+ end
151
+
152
+ # @api private
153
+ # Generates expectation expressions for the `should` syntax.
154
+ module ShouldExpressionGenerator
155
+ def self.positive_expression(target_expression, matcher_expression)
156
+ "#{target_expression}.should #{matcher_expression}"
157
+ end
158
+
159
+ def self.negative_expression(target_expression, matcher_expression)
160
+ "#{target_expression}.should_not #{matcher_expression}"
161
+ end
162
+ end
163
+
164
+ # @api private
165
+ # Generates expectation expressions for the `expect` syntax.
166
+ module ExpectExpressionGenerator
167
+ def self.positive_expression(target_expression, matcher_expression)
168
+ "expect(#{target_expression}).to #{matcher_expression}"
169
+ end
170
+
171
+ def self.negative_expression(target_expression, matcher_expression)
172
+ "expect(#{target_expression}).not_to #{matcher_expression}"
173
+ end
174
+ end
175
+ end
121
176
  end
122
177
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module CollectionMatchers
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -105,6 +105,17 @@ describe "have matcher" do
105
105
  end
106
106
 
107
107
  describe "expect(...).to have(n).items where result responds to items but returns something other than a collection" do
108
+ it "provides a meaningful error" do
109
+ owner = Class.new do
110
+ def items
111
+ 1
112
+ end
113
+ end.new
114
+ expect do
115
+ expect(owner).to have(3).items
116
+ end.to raise_error("expected items to be a collection but it does not respond to #length, #size or #count")
117
+ end
118
+
108
119
  it "provides a meaningful error" do
109
120
  owner = Class.new do
110
121
  def items
@@ -333,7 +344,7 @@ EOF
333
344
 
334
345
  it "passes block to target" do
335
346
  target = double("target")
336
- block = lambda { 5 }
347
+ block = Proc.new { 5 }
337
348
  target.should_receive(:items).with("arg1","arg2", block).and_return([1,2,3])
338
349
  expect(target).to have(3).items("arg1","arg2", block)
339
350
  end
@@ -485,3 +496,72 @@ EOF
485
496
  end
486
497
  end
487
498
  end
499
+
500
+ module RSpec
501
+ module CollectionMatchers
502
+ describe Syntax do
503
+ describe "expression generation" do
504
+ let(:target) { "foo" }
505
+ let(:expectation) { "eq('bar')" }
506
+ let(:positive_expect_example) { "expect(foo).to eq('bar')" }
507
+ let(:positive_should_example) { "foo.should eq('bar')" }
508
+ let(:negative_expect_example) { "expect(foo).not_to eq('bar')" }
509
+ let(:negative_should_example) { "foo.should_not eq('bar')" }
510
+
511
+ def positive_expression
512
+ Syntax.positive_expression(target, expectation)
513
+ end
514
+
515
+ def negative_expression
516
+ Syntax.negative_expression(target, expectation)
517
+ end
518
+
519
+ context "when only :expect is enabled", :uses_only_expect do
520
+ before do
521
+ expect(Expectations::Syntax.should_enabled?).to be_falsey
522
+ expect(Expectations::Syntax.expect_enabled?).to be_truthy
523
+ end
524
+
525
+ it 'generates a positive expression using the expect syntax' do
526
+ expect(positive_expression).to eq(positive_expect_example)
527
+ end
528
+
529
+ it 'generates a negative expression using the expect syntax' do
530
+ expect(negative_expression).to eq(negative_expect_example)
531
+ end
532
+ end
533
+
534
+ context "when both :should and :expect are enabled", :uses_should do
535
+ before do
536
+ expect(Expectations::Syntax.should_enabled?).to be_truthy
537
+ expect(Expectations::Syntax.expect_enabled?).to be_truthy
538
+ end
539
+
540
+ it 'generates a positive expression using the expect syntax' do
541
+ expect(positive_expression).to eq(positive_expect_example)
542
+ end
543
+
544
+ it 'generates a negative expression using the expect syntax' do
545
+ expect(negative_expression).to eq(negative_expect_example)
546
+ end
547
+ end
548
+
549
+ context "when only :should is enabled", :uses_only_should do
550
+ before do
551
+ Expectations::Syntax.should_enabled?.should be_truthy
552
+ Expectations::Syntax.expect_enabled?.should be_falsey
553
+ end
554
+
555
+ it 'generates a positive expression using the expect syntax' do
556
+ positive_expression.should eq(positive_should_example)
557
+ end
558
+
559
+ it 'generates a negative expression using the expect syntax' do
560
+ negative_expression.should eq(negative_should_example)
561
+ end
562
+ end
563
+ end
564
+
565
+ end
566
+ end
567
+ end
@@ -9,3 +9,42 @@ RSpec.configure do |config|
9
9
 
10
10
  config.order = 'random'
11
11
  end
12
+
13
+ shared_context "with #should enabled", :uses_should do
14
+ orig_syntax = nil
15
+
16
+ before(:all) do
17
+ orig_syntax = RSpec::Matchers.configuration.syntax
18
+ RSpec::Matchers.configuration.syntax = [:expect, :should]
19
+ end
20
+
21
+ after(:all) do
22
+ RSpec::Matchers.configuration.syntax = orig_syntax
23
+ end
24
+ end
25
+
26
+ shared_context "with #should exclusively enabled", :uses_only_should do
27
+ orig_syntax = nil
28
+
29
+ before(:all) do
30
+ orig_syntax = RSpec::Matchers.configuration.syntax
31
+ RSpec::Matchers.configuration.syntax = :should
32
+ end
33
+
34
+ after(:all) do
35
+ RSpec::Matchers.configuration.syntax = orig_syntax
36
+ end
37
+ end
38
+
39
+ shared_context "with #expect exclusively enabled", :uses_only_expect do
40
+ orig_syntax = nil
41
+
42
+ before(:all) do
43
+ orig_syntax = RSpec::Matchers.configuration.syntax
44
+ RSpec::Matchers.configuration.syntax = :expect
45
+ end
46
+
47
+ after(:all) do
48
+ RSpec::Matchers.configuration.syntax = orig_syntax
49
+ end
50
+ end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-collection_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Hugo Baraúna
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-11-08 00:00:00.000000000 Z
12
+ date: 2014-02-17 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rspec-expectations
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ! '>='
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ! '>='
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: bundler
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ~>
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ~>
39
44
  - !ruby/object:Gem::Version
@@ -48,6 +53,7 @@ files:
48
53
  - .gitignore
49
54
  - .rspec
50
55
  - .travis.yml
56
+ - Changelog.md
51
57
  - Gemfile
52
58
  - LICENSE.txt
53
59
  - README.md
@@ -68,27 +74,34 @@ files:
68
74
  homepage: https://github.com/rspec/rspec-collection_matchers
69
75
  licenses:
70
76
  - MIT
71
- metadata: {}
72
77
  post_install_message:
73
78
  rdoc_options: []
74
79
  require_paths:
75
80
  - lib
76
81
  required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
77
83
  requirements:
78
84
  - - ! '>='
79
85
  - !ruby/object:Gem::Version
80
86
  version: '0'
87
+ segments:
88
+ - 0
89
+ hash: -3346654767301501509
81
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
82
92
  requirements:
83
93
  - - ! '>='
84
94
  - !ruby/object:Gem::Version
85
95
  version: '0'
96
+ segments:
97
+ - 0
98
+ hash: -3346654767301501509
86
99
  requirements: []
87
100
  rubyforge_project:
88
- rubygems_version: 2.0.7
101
+ rubygems_version: 1.8.23
89
102
  signing_key:
90
- specification_version: 4
91
- summary: rspec-collection_matchers-0.0.2
103
+ specification_version: 3
104
+ summary: rspec-collection_matchers-0.0.3
92
105
  test_files:
93
106
  - features/have.feature
94
107
  - features/support/env.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZjEwMzdhODUyN2ZiZDY4ZmMzZGIyM2YwM2IzYTFiNmFkOTY1ODczMA==
5
- data.tar.gz: !binary |-
6
- YjllMDY2MTVlYTk3ZTViMTBlNWJjN2Y1NWIwZmRlNGQ1NTFiNTI0Mw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- YzAwZTFlNjNmMjE4ZjVkYzBlZWJlZGVhMzMwMmFhOTk1ODJiOGYyZTlmNTY5
10
- ZWU0YjhmODUwNzU3ODcxYWRmNGJiZDc5MmI2YjgwMDY1MDg0YjE0MTIwNzE4
11
- M2EwYTQ5OTIwN2IzN2NlMzQ3NzY2ZGE5NjcwMmQ5NTc2ZDIwYTM=
12
- data.tar.gz: !binary |-
13
- ODNiNTA1OTVhNjlmOTBkM2VlYTY5YTUwZmE1N2ZkOGQ3YTNhNjAyZjRkY2U5
14
- MmVmMzg4YWFkMGI2OWI0YzI3YjRhZjY5YWJhNGVkMmZjYzlkOTY0M2ZhOTM1
15
- MDhkMTUzNGRmM2Y3YTgyYjEwYjUwMTE5ODcwZTQ4NjYxNGNlY2I=