shoulda-matchers 1.0.0.beta3 → 1.0.0

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.
data/Appraisals CHANGED
@@ -1,12 +1,11 @@
1
- appraise "3.0.3" do
2
- gem "rails", "3.0.3"
3
- gem "rake", "~> 0.8.7"
1
+ appraise "3.0" do
2
+ gem "rails", "3.0.10"
4
3
  end
5
4
 
6
- appraise "3.1.0.rc1" do
7
- gem "rails", "3.1.0.rc1"
8
- gem 'sass'
9
- gem 'coffee-script'
5
+ appraise "3.1" do
6
+ gem "rails", "3.1.0"
10
7
  gem 'uglifier'
11
8
  gem 'jquery-rails'
9
+ gem 'coffee-rails'
10
+ gem 'sass-rails'
12
11
  end
data/Gemfile CHANGED
@@ -1,5 +1,12 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  gemspec
4
- gem 'rake', '~> 0.8.7'
4
+ gem 'rake', '~> 0.9.2'
5
5
 
6
+ # For test Rails application
7
+ gem 'sqlite3', :platform => :ruby
8
+ gem 'activerecord-jdbc-adapter', :platform => :jruby
9
+ gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
10
+ gem 'jdbc-sqlite3', :platform => :jruby
11
+ gem 'jruby-openssl', :platform => :jruby
12
+ gem 'shoulda-context', '~> 1.0.0.beta1'
data/Gemfile.lock ADDED
@@ -0,0 +1,115 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ shoulda-matchers (1.0.0.beta3)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ actionpack (3.1.1)
10
+ activemodel (= 3.1.1)
11
+ activesupport (= 3.1.1)
12
+ builder (~> 3.0.0)
13
+ erubis (~> 2.7.0)
14
+ i18n (~> 0.6)
15
+ rack (~> 1.3.2)
16
+ rack-cache (~> 1.1)
17
+ rack-mount (~> 0.8.2)
18
+ rack-test (~> 0.6.1)
19
+ sprockets (~> 2.0.2)
20
+ activemodel (3.1.1)
21
+ activesupport (= 3.1.1)
22
+ builder (~> 3.0.0)
23
+ i18n (~> 0.6)
24
+ activesupport (3.1.1)
25
+ multi_json (~> 1.0)
26
+ appraisal (0.3.8)
27
+ bundler
28
+ rake
29
+ aruba (0.4.5)
30
+ bcat (>= 0.6.1)
31
+ childprocess (>= 0.1.9)
32
+ cucumber (>= 0.10.7)
33
+ rdiscount (>= 1.6.8)
34
+ rspec (>= 2.6.0)
35
+ bcat (0.6.2)
36
+ rack (~> 1.0)
37
+ builder (3.0.0)
38
+ childprocess (0.2.2)
39
+ ffi (~> 1.0.6)
40
+ cucumber (0.10.7)
41
+ builder (>= 2.1.2)
42
+ diff-lcs (>= 1.1.2)
43
+ gherkin (~> 2.4.0)
44
+ json (>= 1.4.6)
45
+ term-ansicolor (>= 1.0.5)
46
+ diff-lcs (1.1.3)
47
+ erubis (2.7.0)
48
+ ffi (1.0.10)
49
+ gherkin (2.4.21)
50
+ json (>= 1.4.6)
51
+ hike (1.2.1)
52
+ i18n (0.6.0)
53
+ json (1.6.1)
54
+ mocha (0.9.12)
55
+ multi_json (1.0.3)
56
+ rack (1.3.5)
57
+ rack-cache (1.1)
58
+ rack (>= 0.4)
59
+ rack-mount (0.8.3)
60
+ rack (>= 1.0.0)
61
+ rack-ssl (1.3.2)
62
+ rack
63
+ rack-test (0.6.1)
64
+ rack (>= 1.0)
65
+ railties (3.1.1)
66
+ actionpack (= 3.1.1)
67
+ activesupport (= 3.1.1)
68
+ rack-ssl (~> 1.3.2)
69
+ rake (>= 0.8.7)
70
+ rdoc (~> 3.4)
71
+ thor (~> 0.14.6)
72
+ rake (0.9.2.2)
73
+ rdiscount (1.6.8)
74
+ rdoc (3.11)
75
+ json (~> 1.4)
76
+ rspec (2.6.0)
77
+ rspec-core (~> 2.6.0)
78
+ rspec-expectations (~> 2.6.0)
79
+ rspec-mocks (~> 2.6.0)
80
+ rspec-core (2.6.4)
81
+ rspec-expectations (2.6.0)
82
+ diff-lcs (~> 1.1.2)
83
+ rspec-mocks (2.6.0)
84
+ rspec-rails (2.6.1)
85
+ actionpack (~> 3.0)
86
+ activesupport (~> 3.0)
87
+ railties (~> 3.0)
88
+ rspec (~> 2.6.0)
89
+ shoulda-context (1.0.0.beta1)
90
+ sprockets (2.0.3)
91
+ hike (~> 1.2)
92
+ rack (~> 1.0)
93
+ tilt (~> 1.1, != 1.3.0)
94
+ sqlite3 (1.3.4)
95
+ term-ansicolor (1.0.7)
96
+ thor (0.14.6)
97
+ tilt (1.3.3)
98
+
99
+ PLATFORMS
100
+ ruby
101
+
102
+ DEPENDENCIES
103
+ activerecord-jdbc-adapter
104
+ activerecord-jdbcsqlite3-adapter
105
+ appraisal (~> 0.3.4)
106
+ aruba
107
+ cucumber (~> 0.10.0)
108
+ jdbc-sqlite3
109
+ jruby-openssl
110
+ mocha (~> 0.9.10)
111
+ rake (~> 0.9.2)
112
+ rspec-rails (~> 2.6.1.beta1)
113
+ shoulda-context (~> 1.0.0.beta1)
114
+ shoulda-matchers!
115
+ sqlite3
data/README.rdoc CHANGED
@@ -8,6 +8,8 @@ These tests would otherwise be much longer, more complex, and error-prone.
8
8
  Refer to the {shoulda}[https://github.com/thoughtbot/shoulda] gem if you want to know more
9
9
  about using shoulda with Test::Unit.
10
10
 
11
+ Please report bugs on the {shoulda issue tracker}[https://github.com/thoughtbot/shoulda/issues].
12
+
11
13
  === ActiveRecord Matchers
12
14
 
13
15
  Matchers to test associations:
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'bundler/setup'
3
3
  require 'rake'
4
4
  require 'rake/rdoctask'
5
- require 'rake/gempackagetask'
5
+ require 'rubygems/package_task'
6
6
  require 'rspec/core/rake_task'
7
7
  require 'cucumber/rake/task'
8
8
  require 'appraisal'
@@ -33,7 +33,7 @@ RSpec::Core::RakeTask.new(:coverage) do |t|
33
33
  end
34
34
 
35
35
  eval("$specification = begin; #{IO.read('shoulda-matchers.gemspec')}; end")
36
- Rake::GemPackageTask.new $specification do |pkg|
36
+ Gem::PackageTask.new $specification do |pkg|
37
37
  pkg.need_tar = true
38
38
  pkg.need_zip = true
39
39
  end
@@ -7,14 +7,25 @@ module Shoulda # :nodoc:
7
7
  # Example:
8
8
  #
9
9
  # it { should render_template(:show) }
10
- def render_template(template)
11
- RenderTemplateMatcher.new(template, self)
10
+ #
11
+ # assert that the "_customer" partial was rendered
12
+ # it { should render_template(:partial => '_customer') }
13
+ #
14
+ # assert that the "_customer" partial was rendered twice
15
+ # it { should render_template(:partial => '_customer', :count => 2) }
16
+ #
17
+ # assert that no partials were rendered
18
+ # it { should render_template(:partial => false) }
19
+ def render_template(options = {}, message = nil)
20
+ RenderTemplateMatcher.new(options, message, self)
12
21
  end
13
22
 
14
23
  class RenderTemplateMatcher # :nodoc:
15
24
 
16
- def initialize(template, context)
17
- @template = template.to_s
25
+ def initialize(options, message, context)
26
+ @options = options
27
+ @message = message
28
+ @template = options.is_a?(Hash) ? options[:partial] : options
18
29
  @context = context
19
30
  end
20
31
 
@@ -38,7 +49,7 @@ module Shoulda # :nodoc:
38
49
 
39
50
  def renders_template?
40
51
  begin
41
- @context.send(:assert_template, @template)
52
+ @context.send(:assert_template, @options, @message)
42
53
  @negative_failure_message = "Didn't expect to render #{@template}"
43
54
  true
44
55
  rescue Shoulda::Matchers::AssertionError => error
@@ -16,7 +16,7 @@ module Shoulda # :nodoc:
16
16
  # it { should route(:get, "/posts/new").to(:action => :new) }
17
17
  # it { should route(:post, "/posts").to(:action => :create) }
18
18
  # it { should route(:get, "/posts/1").to(:action => :show, :id => 1) }
19
- # it { should route(:edit, "/posts/1").to(:action => :show, :id => 1) }
19
+ # it { should route(:get, "/posts/1/edit").to(:action => :edit, :id => 1) }
20
20
  # it { should route(:put, "/posts/1").to(:action => :update, :id => 1) }
21
21
  # it { should route(:delete, "/posts/1").
22
22
  # to(:action => :destroy, :id => 1) }
@@ -68,6 +68,7 @@ module Shoulda # :nodoc:
68
68
  def flash
69
69
  return @flash if @flash
70
70
  @flash = @controller.flash.dup
71
+ @flash.instance_variable_set(:@used, @controller.flash.instance_variable_get(:@used).dup)
71
72
  @flash.sweep unless @now
72
73
  @flash
73
74
  end
@@ -3,6 +3,7 @@ require 'shoulda/matchers/active_model/validation_matcher'
3
3
  require 'shoulda/matchers/active_model/allow_value_matcher'
4
4
  require 'shoulda/matchers/active_model/ensure_length_of_matcher'
5
5
  require 'shoulda/matchers/active_model/ensure_inclusion_of_matcher'
6
+ require 'shoulda/matchers/active_model/ensure_exclusion_of_matcher'
6
7
  require 'shoulda/matchers/active_model/validate_presence_of_matcher'
7
8
  require 'shoulda/matchers/active_model/validate_format_of_matcher'
8
9
  require 'shoulda/matchers/active_model/validate_uniqueness_of_matcher'
@@ -0,0 +1,70 @@
1
+ module Shoulda # :nodoc:
2
+ module Matchers
3
+ module ActiveModel # :nodoc:
4
+
5
+ # Ensure that the attribute's value is not in the range specified
6
+ #
7
+ # Options:
8
+ # * <tt>in_range</tt> - the range of not allowed values for this attribute
9
+ # * <tt>with_message</tt> - value the test expects to find in
10
+ # <tt>errors.on(:attribute)</tt>. Regexp or string. Defaults to the
11
+ # translation for :exclusion.
12
+ #
13
+ # Example:
14
+ # it { should ensure_exclusion_of(:age).in_range(30..60) }
15
+ #
16
+ def ensure_exclusion_of(attr)
17
+ EnsureExclusionOfMatcher.new(attr)
18
+ end
19
+
20
+ class EnsureExclusionOfMatcher < ValidationMatcher # :nodoc:
21
+
22
+ def in_range(range)
23
+ @range = range
24
+ @minimum = range.first
25
+ @maximum = range.last
26
+ self
27
+ end
28
+
29
+ def with_message(message)
30
+ @expected_message = message if message
31
+ self
32
+ end
33
+
34
+ def description
35
+ "ensure exclusion of #{@attribute} in #{@range.inspect}"
36
+ end
37
+
38
+ def matches?(subject)
39
+ super(subject)
40
+
41
+ @expected_message ||= :exclusion
42
+
43
+ allows_lower_value &&
44
+ disallows_minimum_value &&
45
+ allows_higher_value &&
46
+ disallows_maximum_value
47
+ end
48
+
49
+ private
50
+
51
+ def allows_lower_value
52
+ @minimum == 0 || allows_value_of(@minimum - 1, @expected_message)
53
+ end
54
+
55
+ def allows_higher_value
56
+ allows_value_of(@maximum + 1, @expected_message)
57
+ end
58
+
59
+ def disallows_minimum_value
60
+ disallows_value_of(@minimum, @expected_message)
61
+ end
62
+
63
+ def disallows_maximum_value
64
+ disallows_value_of(@maximum, @expected_message)
65
+ end
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -116,7 +116,11 @@ module Shoulda # :nodoc:
116
116
  # Assume the scope is a foreign key if the field is nil
117
117
  previous_value ||= 0
118
118
 
119
- next_value = previous_value.next
119
+ next_value = if previous_value.respond_to?(:next)
120
+ previous_value.next
121
+ else
122
+ previous_value.to_s.next
123
+ end
120
124
 
121
125
  @subject.send("#{scope}=", next_value)
122
126
 
@@ -18,6 +18,7 @@ module Shoulda # :nodoc:
18
18
  # * <tt>through</tt> - association name for <tt>has_many :through</tt>
19
19
  # * <tt>dependent</tt> - tests that the association makes use of the
20
20
  # dependent option.
21
+ # * <tt>:class_name</tt> - tests that the association makes use of the class_name option.
21
22
  #
22
23
  # Example:
23
24
  # it { should have_many(:friends) }
@@ -35,6 +36,7 @@ module Shoulda # :nodoc:
35
36
  # Options:
36
37
  # * <tt>:dependent</tt> - tests that the association makes use of the
37
38
  # dependent option.
39
+ # * <tt>:class_name</tt> - tests that the association makes use of the class_name option.
38
40
  #
39
41
  # Example:
40
42
  # it { should have_one(:god) } # unless hindu
@@ -71,7 +73,17 @@ module Shoulda # :nodoc:
71
73
  def order(order)
72
74
  @order = order
73
75
  self
74
- end
76
+ end
77
+
78
+ def conditions(conditions)
79
+ @conditions = conditions
80
+ self
81
+ end
82
+
83
+ def class_name(class_name)
84
+ @class_name = class_name
85
+ self
86
+ end
75
87
 
76
88
  def matches?(subject)
77
89
  @subject = subject
@@ -80,7 +92,9 @@ module Shoulda # :nodoc:
80
92
  foreign_key_exists? &&
81
93
  through_association_valid? &&
82
94
  dependent_correct? &&
95
+ class_name_correct? &&
83
96
  order_correct? &&
97
+ conditions_correct? &&
84
98
  join_table_exists?
85
99
  end
86
100
 
@@ -96,6 +110,7 @@ module Shoulda # :nodoc:
96
110
  description = "#{macro_description} #{@name}"
97
111
  description += " through #{@through}" if @through
98
112
  description += " dependent => #{@dependent}" if @dependent
113
+ description += " class_name => #{@class_name}" if @class_name
99
114
  description += " order => #{@order}" if @order
100
115
  description
101
116
  end
@@ -166,6 +181,15 @@ module Shoulda # :nodoc:
166
181
  end
167
182
  end
168
183
 
184
+ def class_name_correct?
185
+ if @class_name.nil? || @class_name.to_s == reflection.options[:class_name].to_s
186
+ true
187
+ else
188
+ @missing = "#{@name} should have #{@class_name} as class_name"
189
+ false
190
+ end
191
+ end
192
+
169
193
  def order_correct?
170
194
  if @order.nil? || @order.to_s == reflection.options[:order].to_s
171
195
  true
@@ -173,7 +197,16 @@ module Shoulda # :nodoc:
173
197
  @missing = "#{@name} should be ordered by #{@order}"
174
198
  false
175
199
  end
176
- end
200
+ end
201
+
202
+ def conditions_correct?
203
+ if @conditions.nil? || @conditions.to_s == reflection.options[:conditions].to_s
204
+ true
205
+ else
206
+ @missing = "#{@name} should have the following conditions: #{@conditions}"
207
+ false
208
+ end
209
+ end
177
210
 
178
211
  def join_table_exists?
179
212
  if @macro != :has_and_belongs_to_many ||
@@ -58,11 +58,11 @@ module Shoulda # :nodoc:
58
58
 
59
59
  def correct_unique?
60
60
  return true if @unique.nil?
61
- if matched_index.unique == @unique
61
+ if !!matched_index.unique == @unique
62
62
  true
63
63
  else
64
64
  @missing = "#{table_name} has an index named #{matched_index.name} " <<
65
- "of unique #{matched_index.unique}, not #{@unique}."
65
+ "of unique #{!!matched_index.unique}, not #{@unique}."
66
66
  false
67
67
  end
68
68
  end
@@ -5,7 +5,7 @@ module Shoulda # :nodoc:
5
5
  # Ensures that the attribute cannot be changed once the record has been
6
6
  # created.
7
7
  #
8
- # it { should have_readonly_attributes(:password) }
8
+ # it { should have_readonly_attribute(:password) }
9
9
  #
10
10
  def have_readonly_attribute(value)
11
11
  HaveReadonlyAttributeMatcher.new(value)
@@ -1,5 +1,5 @@
1
1
  module Shoulda
2
2
  module Matchers
3
- VERSION = "1.0.0.beta3".dup
3
+ VERSION = "1.0.0".dup
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoulda-matchers
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: 6
5
- version: 1.0.0.beta3
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
6
11
  platform: ruby
7
12
  authors:
8
13
  - Tammer Saleh
@@ -15,75 +20,89 @@ autorequire:
15
20
  bindir: bin
16
21
  cert_chain: []
17
22
 
18
- date: 2011-07-18 00:00:00 -04:00
23
+ date: 2011-11-01 00:00:00 -04:00
19
24
  default_executable:
20
25
  dependencies:
21
26
  - !ruby/object:Gem::Dependency
22
- name: sqlite3-ruby
27
+ name: mocha
23
28
  prerelease: false
24
29
  requirement: &id001 !ruby/object:Gem::Requirement
25
30
  none: false
26
31
  requirements:
27
32
  - - ~>
28
33
  - !ruby/object:Gem::Version
29
- version: 1.3.2
34
+ hash: 47
35
+ segments:
36
+ - 0
37
+ - 9
38
+ - 10
39
+ version: 0.9.10
30
40
  type: :development
31
41
  version_requirements: *id001
32
42
  - !ruby/object:Gem::Dependency
33
- name: mocha
43
+ name: rspec-rails
34
44
  prerelease: false
35
45
  requirement: &id002 !ruby/object:Gem::Requirement
36
46
  none: false
37
47
  requirements:
38
48
  - - ~>
39
49
  - !ruby/object:Gem::Version
40
- version: 0.9.10
50
+ hash: 62196361
51
+ segments:
52
+ - 2
53
+ - 6
54
+ - 1
55
+ - beta
56
+ - 1
57
+ version: 2.6.1.beta1
41
58
  type: :development
42
59
  version_requirements: *id002
43
60
  - !ruby/object:Gem::Dependency
44
- name: rspec-rails
61
+ name: cucumber
45
62
  prerelease: false
46
63
  requirement: &id003 !ruby/object:Gem::Requirement
47
64
  none: false
48
65
  requirements:
49
66
  - - ~>
50
67
  - !ruby/object:Gem::Version
51
- version: 2.6.1.beta1
68
+ hash: 55
69
+ segments:
70
+ - 0
71
+ - 10
72
+ - 0
73
+ version: 0.10.0
52
74
  type: :development
53
75
  version_requirements: *id003
54
76
  - !ruby/object:Gem::Dependency
55
- name: cucumber
77
+ name: appraisal
56
78
  prerelease: false
57
79
  requirement: &id004 !ruby/object:Gem::Requirement
58
80
  none: false
59
81
  requirements:
60
82
  - - ~>
61
83
  - !ruby/object:Gem::Version
62
- version: 0.10.0
84
+ hash: 27
85
+ segments:
86
+ - 0
87
+ - 3
88
+ - 4
89
+ version: 0.3.4
63
90
  type: :development
64
91
  version_requirements: *id004
65
92
  - !ruby/object:Gem::Dependency
66
- name: appraisal
93
+ name: aruba
67
94
  prerelease: false
68
95
  requirement: &id005 !ruby/object:Gem::Requirement
69
96
  none: false
70
97
  requirements:
71
- - - ~>
98
+ - - ">="
72
99
  - !ruby/object:Gem::Version
73
- version: 0.3.4
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
74
104
  type: :development
75
105
  version_requirements: *id005
76
- - !ruby/object:Gem::Dependency
77
- name: ruby-debug19
78
- prerelease: false
79
- requirement: &id006 !ruby/object:Gem::Requirement
80
- none: false
81
- requirements:
82
- - - ~>
83
- - !ruby/object:Gem::Version
84
- version: 0.11.6
85
- type: :development
86
- version_requirements: *id006
87
106
  description: Making tests easy on the fingers and eyes
88
107
  email: support@thoughtbot.com
89
108
  executables: []
@@ -97,6 +116,7 @@ files:
97
116
  - Appraisals
98
117
  - CONTRIBUTION_GUIDELINES.rdoc
99
118
  - Gemfile
119
+ - Gemfile.lock
100
120
  - MIT-LICENSE
101
121
  - Rakefile
102
122
  - README.rdoc
@@ -115,6 +135,7 @@ files:
115
135
  - lib/shoulda/matchers/action_mailer.rb
116
136
  - lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb
117
137
  - lib/shoulda/matchers/active_model/allow_value_matcher.rb
138
+ - lib/shoulda/matchers/active_model/ensure_exclusion_of_matcher.rb
118
139
  - lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb
119
140
  - lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb
120
141
  - lib/shoulda/matchers/active_model/helpers.rb
@@ -152,12 +173,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
173
  requirements:
153
174
  - - ">="
154
175
  - !ruby/object:Gem::Version
176
+ hash: 3
177
+ segments:
178
+ - 0
155
179
  version: "0"
156
180
  required_rubygems_version: !ruby/object:Gem::Requirement
157
181
  none: false
158
182
  requirements:
159
183
  - - ">="
160
184
  - !ruby/object:Gem::Version
185
+ hash: 3
186
+ segments:
187
+ - 0
161
188
  version: "0"
162
189
  requirements: []
163
190