Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use current thoughtbot style in specs

  • Loading branch information...
commit af8f9a7bffa238db2648dfc28f23b7618f6881f2 1 parent cc03053
@gabebw gabebw authored
Showing with 1,880 additions and 2,167 deletions.
  1. +7 −7 features/step_definitions/rails_steps.rb
  2. +1 −1  features/support/env.rb
  3. +3 −3 gemfiles/3.0.gemfile.lock
  4. +3 −3 gemfiles/3.1.gemfile.lock
  5. +4 −4 gemfiles/3.2.gemfile.lock
  6. +2 −2 lib/shoulda/matchers/action_controller.rb
  7. +0 −1  lib/shoulda/matchers/action_controller/assign_to_matcher.rb
  8. +0 −1  lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
  9. +0 −1  lib/shoulda/matchers/action_controller/render_template_matcher.rb
  10. +4 −4 lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb
  11. +8 −8 lib/shoulda/matchers/action_controller/route_matcher.rb
  12. +1 −2  lib/shoulda/matchers/action_controller/set_session_matcher.rb
  13. +8 −7 lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb
  14. +2 −2 lib/shoulda/matchers/action_mailer/have_sent_email_matcher.rb
  15. +1 −1  lib/shoulda/matchers/active_model.rb
  16. +3 −3 lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb
  17. +2 −2 lib/shoulda/matchers/active_model/allow_value_matcher.rb
  18. +1 −1  lib/shoulda/matchers/active_model/disallow_value_matcher.rb
  19. +1 −1  lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb
  20. +0 −1  lib/shoulda/matchers/active_model/exception_message_finder.rb
  21. +1 −1  lib/shoulda/matchers/active_model/only_integer_matcher.rb
  22. +8 −6 lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb
  23. +15 −9 lib/shoulda/matchers/active_model/validate_format_of_matcher.rb
  24. +2 −2 lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb
  25. +9 −10 lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb
  26. +1 −1  lib/shoulda/matchers/active_model/validation_message_finder.rb
  27. +3 −3 lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb
  28. +1 −1  lib/shoulda/matchers/active_record/association_matcher.rb
  29. +9 −5 lib/shoulda/matchers/active_record/have_db_column_matcher.rb
  30. +1 −1  lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb
  31. +1 −1  lib/shoulda/matchers/active_record/serialize_matcher.rb
  32. +2 −2 lib/shoulda/matchers/assertion_error.rb
  33. +19 −16 spec/shoulda/matchers/action_controller/assign_to_matcher_spec.rb
  34. +15 −13 spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb
  35. +19 −17 spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb
  36. +40 −31 spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb
  37. +28 −25 spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb
  38. +20 −17 spec/shoulda/matchers/action_controller/respond_with_content_type_matcher_spec.rb
  39. +18 −70 spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb
  40. +28 −28 spec/shoulda/matchers/action_controller/route_matcher_spec.rb
  41. +29 −24 spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
  42. +91 −66 spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb
  43. +95 −104 spec/shoulda/matchers/action_mailer/have_sent_email_spec.rb
  44. +54 −58 spec/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb
  45. +64 −71 spec/shoulda/matchers/active_model/allow_value_matcher_spec.rb
  46. +20 −42 spec/shoulda/matchers/active_model/disallow_value_matcher_spec.rb
  47. +39 −50 spec/shoulda/matchers/active_model/ensure_exclusion_of_matcher_spec.rb
  48. +102 −112 spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb
  49. +63 −89 spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb
  50. +2 −2 spec/shoulda/matchers/active_model/exception_message_finder_spec.rb
  51. +98 −87 spec/shoulda/matchers/active_model/helpers_spec.rb
  52. +30 −45 spec/shoulda/matchers/active_model/only_integer_matcher_spec.rb
  53. +23 −25 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
  54. +23 −30 spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb
  55. +50 −47 spec/shoulda/matchers/active_model/validate_format_of_matcher_spec.rb
  56. +41 −80 spec/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb
  57. +66 −74 spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb
  58. +113 −92 spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb
  59. +0 −1  spec/shoulda/matchers/active_model/validation_message_finder_spec.rb
  60. +69 −47 spec/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb
  61. +268 −377 spec/shoulda/matchers/active_record/association_matcher_spec.rb
  62. +66 −140 spec/shoulda/matchers/active_record/have_db_column_matcher_spec.rb
  63. +36 −63 spec/shoulda/matchers/active_record/have_db_index_matcher_spec.rb
  64. +24 −29 spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
  65. +10 −10 spec/shoulda/matchers/active_record/query_the_database_matcher_spec.rb
  66. +59 −53 spec/shoulda/matchers/active_record/serialize_matcher_spec.rb
  67. +23 −29 spec/shoulda/matchers/independent/delegate_matcher_spec.rb
  68. +1 −1  spec/spec_helper.rb
  69. +19 −0 spec/support/activemodel_helpers.rb
  70. +3 −3 spec/support/controller_builder.rb
  71. +8 −2 spec/support/model_builder.rb
View
14 features/step_definitions/rails_steps.rb
@@ -25,8 +25,8 @@
And I set the "BUNDLE_GEMFILE" environment variable to "Gemfile"
And I successfully run `bundle install --local`
}
- if RUBY_VERSION >= "1.9.3"
- append_to_gemfile %(gem "rake", "~> 0.9.3.beta.1")
+ if RUBY_VERSION >= '1.9.3'
+ append_to_gemfile %(gem 'rake', '~> 0.9.3.beta.1')
step %(I successfully run `bundle update rake`)
end
end
@@ -52,7 +52,7 @@
end
When 'I configure the application to use rspec-rails' do
- append_to_gemfile "gem 'rspec-rails', '~> 2.8.1'"
+ append_to_gemfile %q(gem 'rspec-rails', '~> 2.8.1')
steps %{And I run `bundle install --local`}
end
@@ -66,7 +66,7 @@
end
When 'I configure the application to use shoulda-context' do
- append_to_gemfile "gem 'shoulda-context', '~> 1.0.0'"
+ append_to_gemfile %q(gem 'shoulda-context', '~> 1.0.0')
steps %{And I run `bundle install --local`}
end
@@ -106,7 +106,7 @@
module FileHelpers
def append_to(path, contents)
in_current_dir do
- File.open(path, "a") do |file|
+ File.open(path, 'a') do |file|
file.puts
file.puts contents
end
@@ -119,9 +119,9 @@ def append_to_gemfile(contents)
def comment_out_gem_in_gemfile(gemname)
in_current_dir do
- gemfile = File.read("Gemfile")
+ gemfile = File.read('Gemfile')
gemfile.sub!(/^(\s*)(gem\s*['"]#{gemname})/, "\\1# \\2")
- File.open("Gemfile", 'w'){ |file| file.write(gemfile) }
+ File.open('Gemfile', 'w'){ |file| file.write(gemfile) }
end
end
end
View
2  features/support/env.rb
@@ -1,5 +1,5 @@
require 'aruba/cucumber'
Before do
- @aruba_timeout_seconds = 120
+ @aruba_timeout_seconds = 60 * 2
end
View
6 gemfiles/3.0.gemfile.lock
@@ -1,5 +1,5 @@
PATH
- remote: /Users/draper/Dropbox/Development/shoulda-matchers
+ remote: /Users/gabe/thoughtbot/open-source/shoulda-matchers
specs:
shoulda-matchers (1.4.2)
activesupport (>= 3.0.0)
@@ -90,7 +90,7 @@ GEM
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.4)
- rake (10.0.2)
+ rake (10.0.3)
rdoc (3.12)
json (~> 1.4)
rspec (2.8.0)
@@ -106,7 +106,7 @@ GEM
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.8.0)
- shoulda-context (1.0.1)
+ shoulda-context (1.0.2)
sqlite3 (1.3.6)
thor (0.14.6)
treetop (1.4.12)
View
6 gemfiles/3.1.gemfile.lock
@@ -1,5 +1,5 @@
PATH
- remote: /Users/draper/Dropbox/Development/shoulda-matchers
+ remote: /Users/gabe/thoughtbot/open-source/shoulda-matchers
specs:
shoulda-matchers (1.4.2)
activesupport (>= 3.0.0)
@@ -99,7 +99,7 @@ GEM
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
- rake (10.0.2)
+ rake (10.0.3)
rdoc (3.12)
json (~> 1.4)
rspec (2.8.0)
@@ -121,7 +121,7 @@ GEM
railties (~> 3.1.0)
sass (>= 3.1.10)
tilt (~> 1.3.2)
- shoulda-context (1.0.1)
+ shoulda-context (1.0.2)
sprockets (2.0.4)
hike (~> 1.2)
rack (~> 1.0)
View
8 gemfiles/3.2.gemfile.lock
@@ -1,5 +1,5 @@
PATH
- remote: /Users/draper/Dropbox/Development/shoulda-matchers
+ remote: /Users/gabe/thoughtbot/open-source/shoulda-matchers
specs:
shoulda-matchers (1.4.2)
activesupport (>= 3.0.0)
@@ -73,7 +73,7 @@ GEM
mime-types (1.19)
mocha (0.12.7)
metaclass (~> 0.0.1)
- multi_json (1.4.0)
+ multi_json (1.5.0)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
@@ -97,7 +97,7 @@ GEM
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
- rake (10.0.2)
+ rake (10.0.3)
rdoc (3.12)
json (~> 1.4)
rspec (2.8.0)
@@ -118,7 +118,7 @@ GEM
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
- shoulda-context (1.0.1)
+ shoulda-context (1.0.2)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
View
4 lib/shoulda/matchers/action_controller.rb
@@ -16,7 +16,7 @@ module Matchers
#
# This code segment:
#
- # describe UsersController, "on GET to show with a valid id" do
+ # describe UsersController, 'on GET to show with a valid id' do
# before(:each) do
# get :show, :id => User.first.to_param
# end
@@ -26,7 +26,7 @@ module Matchers
# it { should render_template(:show) }
# it { should not_set_the_flash) }
#
- # it "should do something else really cool" do
+ # it 'does something else really cool' do
# assigns[:user].id.should == 1
# end
# end
View
1  lib/shoulda/matchers/action_controller/assign_to_matcher.rb
@@ -1,7 +1,6 @@
module Shoulda # :nodoc:
module Matchers
module ActionController # :nodoc:
-
# Ensures that the controller assigned to the named instance variable.
#
# Options:
View
1  lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
@@ -1,7 +1,6 @@
module Shoulda # :nodoc:
module Matchers
module ActionController # :nodoc:
-
# Ensures a controller redirected to the given url.
#
# Example:
View
1  lib/shoulda/matchers/action_controller/render_template_matcher.rb
@@ -1,7 +1,6 @@
module Shoulda # :nodoc:
module Matchers
module ActionController # :nodoc:
-
# Ensures a controller rendered the given template.
#
# Example:
View
8 lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb
@@ -42,9 +42,9 @@ def negative_failure_message
end
def description
- description = "render with "
+ description = 'render with '
if @expected_layout.nil?
- description << "a layout"
+ description << 'a layout'
else
description << "the #{@expected_layout.inspect} layout"
end
@@ -83,9 +83,9 @@ def expectation
def result
if rendered_with_layout?
- "rendered with " + rendered_layouts.map(&:inspect).join(", ")
+ 'rendered with ' + rendered_layouts.map(&:inspect).join(', ')
else
- "rendered without a layout"
+ 'rendered without a layout'
end
end
end
View
16 lib/shoulda/matchers/action_controller/route_matcher.rb
@@ -11,16 +11,16 @@ module ActionController # :nodoc:
#
# Examples:
#
- # it { should route(:get, "/posts").
+ # it { should route(:get, '/posts').
# to(:controller => :posts, :action => :index) }
- # it { should route(:get, "/posts/new").to(:action => :new) }
- # it { should route(:post, "/posts").to(:action => :create) }
- # it { should route(:get, "/posts/1").to(:action => :show, :id => 1) }
- # it { should route(:get, "/posts/1/edit").to(:action => :edit, :id => 1) }
- # it { should route(:put, "/posts/1").to(:action => :update, :id => 1) }
- # it { should route(:delete, "/posts/1").
+ # it { should route(:get, '/posts/new').to(:action => :new) }
+ # it { should route(:post, '/posts').to(:action => :create) }
+ # it { should route(:get, '/posts/1').to(:action => :show, :id => 1) }
+ # it { should route(:get, '/posts/1/edit').to(:action => :edit, :id => 1) }
+ # it { should route(:put, '/posts/1').to(:action => :update, :id => 1) }
+ # it { should route(:delete, '/posts/1').
# to(:action => :destroy, :id => 1) }
- # it { should route(:get, "/users/1/posts/1").
+ # it { should route(:get, '/users/1/posts/1').
# to(:action => :show, :id => 1, :user_id => 1) }
def route(method, path)
RouteMatcher.new(method, path, self)
View
3  lib/shoulda/matchers/action_controller/set_session_matcher.rb
@@ -82,12 +82,11 @@ def expectation
if @value
expectation << " to #{@value.inspect}"
end
- expectation
end
def result
if session.empty?
- "no session variables were set"
+ 'no session variables were set'
else
"the session was #{session.inspect}"
end
View
15 lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb
@@ -8,9 +8,9 @@ module ActionController # :nodoc:
# Example:
#
# it { should set_the_flash }
- # it { should set_the_flash.to("Thank you for placing this order.") }
+ # it { should set_the_flash.to('Thank you for placing this order.') }
# it { should set_the_flash.to(/created/i) }
- # it { should set_the_flash[:alert].to("Password doesn't match") }
+ # it { should set_the_flash[:alert].to('Password does not match') }
# it { should set_the_flash.to(/logged in/i).now }
# it { should_not set_the_flash }
def set_the_flash
@@ -96,7 +96,8 @@ def flash
@flash
else
@flash = @controller.flash.dup
- @flash.instance_variable_set(:@used, @controller.flash.instance_variable_get(:@used).dup)
+ used = @controller.flash.instance_variable_get(:@used).dup
+ @flash.instance_variable_set(:@used, used)
sweep_flash_if_necessary
@flash
end
@@ -117,7 +118,7 @@ def expectation
def flash_description
if flash.blank?
- "no flash was set"
+ 'no flash was set'
else
"was #{flash.inspect}"
end
@@ -129,9 +130,9 @@ def expected_flash_invocation
def pretty_now
if @options[:now]
- ".now"
+ '.now'
else
- ""
+ ''
end
end
@@ -139,7 +140,7 @@ def pretty_key
if @options[:key]
"[:#{@options[:key]}]"
else
- ""
+ ''
end
end
end
View
4 lib/shoulda/matchers/action_mailer/have_sent_email_matcher.rb
@@ -115,7 +115,7 @@ def negative_failure_message
end
def description
- description = "send an email"
+ description = 'send an email'
description << " with a subject of #{@email_subject.inspect}" if @email_subject
description << " containing #{@body.inspect}" if @body
if @parts
@@ -136,7 +136,7 @@ def description
private
def expectation
- expectation = "sent email"
+ expectation = 'sent email'
expectation << " with subject #{@email_subject.inspect}" if @subject_failed
expectation << " with body #{@body.inspect}" if @body_failed
@parts.each do |_, body, content_type|
View
2  lib/shoulda/matchers/active_model.rb
@@ -30,7 +30,7 @@ module Matchers
# %w(abcd 1234).each do |value|
# it { should_not allow_value(value).for(:phone_number) }
# end
- # it { should allow_value("(123) 456-7890").for(:phone_number) }
+ # it { should allow_value('(123) 456-7890').for(:phone_number) }
# it { should_not allow_mass_assignment_of(:password) }
# it { should allow_value('Activated', 'Pending').for(:status).strict }
# it { should_not allow_value('Amazing').for(:status).strict }
View
6 lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb
@@ -25,7 +25,7 @@ def initialize(attribute)
def as(role)
if active_model_less_than_3_1?
- raise "You can specify role only in Rails 3.1 or greater"
+ raise 'You can specify role only in Rails 3.1 or greater'
end
@options[:role] = role
self
@@ -38,7 +38,7 @@ def matches?(subject)
@negative_failure_message = "#{@attribute} was made accessible"
else
if protected_attributes.empty?
- @negative_failure_message = "no attributes were protected"
+ @negative_failure_message = 'no attributes were protected'
else
@negative_failure_message = "#{class_name} is protecting " <<
"#{protected_attributes.to_a.to_sentence}, " <<
@@ -57,7 +57,7 @@ def matches?(subject)
end
def description
- [base_description, role_description].compact.join(" ")
+ [base_description, role_description].compact.join(' ')
end
private
View
4 lib/shoulda/matchers/active_model/allow_value_matcher.rb
@@ -17,11 +17,11 @@ module ActiveModel # :nodoc:
#
# Example:
# it { should_not allow_value('bad').for(:isbn) }
- # it { should allow_value("isbn 1 2345 6789 0").for(:isbn) }
+ # it { should allow_value('isbn 1 2345 6789 0').for(:isbn) }
#
def allow_value(*values)
if values.empty?
- raise ArgumentError, "need at least one argument"
+ raise ArgumentError, 'need at least one argument'
else
AllowValueMatcher.new(*values)
end
View
2  lib/shoulda/matchers/active_model/disallow_value_matcher.rb
@@ -25,7 +25,7 @@ def failure_message
end
def allowed_types
- ""
+ ''
end
end
end
View
2  lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb
@@ -22,7 +22,7 @@ def ensure_inclusion_of(attr)
end
class EnsureInclusionOfMatcher < ValidationMatcher # :nodoc:
- ARBITRARY_OUTSIDE_STRING = "shouldamatchersteststring"
+ ARBITRARY_OUTSIDE_STRING = 'shouldamatchersteststring'
def initialize(attribute)
super(attribute)
View
1  lib/shoulda/matchers/active_model/exception_message_finder.rb
@@ -1,7 +1,6 @@
module Shoulda
module Matchers
module ActiveModel
-
# Finds message information from exceptions thrown by #valid?
class ExceptionMessageFinder
def initialize(instance, attribute)
View
2  lib/shoulda/matchers/active_model/only_integer_matcher.rb
@@ -21,7 +21,7 @@ def with_message(message)
end
def allowed_types
- "integer"
+ 'integer'
end
def failure_message
View
14 lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb
@@ -39,23 +39,25 @@ def matches?(subject)
private
def disallows_different_value
- set_confirmation("some value")
- matches = disallows_value_of("different value", @message)
+ set_confirmation('some value')
+ disallows_value_of('different value', @message)
end
def allows_same_value
- set_confirmation("same value")
- allows_value_of("same value", @message)
+ set_confirmation('same value')
+ allows_value_of('same value', @message)
end
def allows_missing_confirmation
set_confirmation(nil)
- allows_value_of("any value", @message)
+ allows_value_of('any value', @message)
end
def set_confirmation(val)
setter = :"#{@confirmation}="
- @subject.send(setter, val) if @subject.respond_to?(setter)
+ if @subject.respond_to?(setter)
+ @subject.send(setter, val)
+ end
end
end
end
View
24 lib/shoulda/matchers/active_model/validate_format_of_matcher.rb
@@ -1,7 +1,6 @@
module Shoulda # :nodoc:
module Matchers
module ActiveModel # :nodoc:
-
# Ensures that the model is not valid if the given attribute is not
# formatted correctly.
#
@@ -27,7 +26,6 @@ def validate_format_of(attr)
end
class ValidateFormatOfMatcher < ValidationMatcher # :nodoc:
-
def initialize(attribute)
super
@options = {}
@@ -44,20 +42,28 @@ def allow_nil(allow_nil = true)
end
def with_message(message)
- @expected_message = message if message
+ if message
+ @expected_message = message
+ end
self
end
def with(value)
- raise "You may not call both with and not_with" if @value_to_fail
- @value_to_pass = value
- self
+ if @value_to_fail
+ raise 'You may not call both with and not_with'
+ else
+ @value_to_pass = value
+ self
+ end
end
def not_with(value)
- raise "You may not call both with and not_with" if @value_to_pass
- @value_to_fail = value
- self
+ if @value_to_pass
+ raise 'You may not call both with and not_with'
+ else
+ @value_to_fail = value
+ self
+ end
end
def matches?(subject)
View
4 lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb
@@ -79,8 +79,8 @@ def failing_submatchers
end
def allowed_types
- allowed = ["numeric"] + submatcher_allowed_types
- allowed.join(", ")
+ allowed = ['numeric'] + submatcher_allowed_types
+ allowed.join(', ')
end
def submatcher_allowed_types
View
19 lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb
@@ -1,7 +1,6 @@
module Shoulda # :nodoc:
module Matchers
module ActiveModel # :nodoc:
-
# Ensures that the model is invalid if the given attribute is not unique.
#
# Internally, this uses values from existing records to test validations,
@@ -57,14 +56,6 @@ def case_insensitive
self
end
- def description
- result = "require "
- result << "case sensitive " unless @options[:case_insensitive]
- result << "unique value for #{@attribute}"
- result << " scoped to #{@options[:scopes].join(', ')}" if @options[:scopes].present?
- result
- end
-
def matches?(subject)
@subject = subject.class.new
@expected_message ||= :taken
@@ -73,6 +64,14 @@ def matches?(subject)
validate_after_scope_change?
end
+ def description
+ result = 'require '
+ result << 'case sensitive ' unless @options[:case_insensitive]
+ result << "unique value for #{@attribute}"
+ result << " scoped to #{@options[:scopes].join(', ')}" if @options[:scopes].present?
+ result
+ end
+
private
def existing
@@ -85,7 +84,7 @@ def first_instance
def create_instance_in_database
@subject.class.new.tap do |instance|
- instance.send("#{@attribute}=", "arbitrary_string")
+ instance.send("#{@attribute}=", 'arbitrary_string')
instance.save(:validate => false)
end
end
View
2  lib/shoulda/matchers/active_model/validation_message_finder.rb
@@ -29,7 +29,7 @@ def source_description
def messages_description
if errors.empty?
- "no errors"
+ 'no errors'
else
"errors: #{pretty_error_messages(validated_instance)}"
end
View
6 lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb
@@ -78,7 +78,7 @@ def exists?
if config
true
else
- @problem = "is not declared"
+ @problem = 'is not declared'
false
end
end
@@ -129,9 +129,9 @@ def expectation
def should_or_should_not(value)
if value
- "should"
+ 'should'
else
- "should not"
+ 'should not'
end
end
end
View
2  lib/shoulda/matchers/active_record/association_matcher.rb
@@ -260,7 +260,7 @@ def validate_correct?
if !@validate && !reflection.options[:validate] || @validate == reflection.options[:validate]
true
else
- @missing = "#{@name} should have #{@validate} as validate"
+ @missing = "#{@name} should have :validate => #{@validate}"
false
end
end
View
14 lib/shoulda/matchers/active_record/have_db_column_matcher.rb
@@ -149,11 +149,11 @@ def correct_null?
def correct_scale?
return true unless @options.key?(:scale)
- if matched_column.scale.to_s == @options[:scale].to_s
+ if actual_scale.to_s == @options[:scale].to_s
true
else
- @missing = "#{model_class} has a db column named #{@column} " <<
- "of scale #{matched_column.scale}, not #{@options[:scale]}."
+ @missing = "#{model_class} has a db column named #{@column} "
+ @missing << "of scale #{actual_scale}, not #{@options[:scale]}."
false
end
end
@@ -166,9 +166,9 @@ def correct_primary?
else
@missing = "#{model_class} has a db column named #{@column} "
if @options[:primary]
- @missing << "that is not primary, but should be"
+ @missing << 'that is not primary, but should be'
else
- @missing << "that is primary, but should not be"
+ @missing << 'that is primary, but should not be'
end
false
end
@@ -182,6 +182,10 @@ def model_class
@subject.class
end
+ def actual_scale
+ matched_column.scale
+ end
+
def expectation
expected = "#{model_class.name} to #{description}"
end
View
2  lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb
@@ -26,7 +26,7 @@ def matches?(subject)
else
if readonly_attributes.empty?
@failure_message = "#{class_name} attribute #{@attribute} " <<
- "is not read-only"
+ 'is not read-only'
else
@failure_message = "#{class_name} is making " <<
"#{readonly_attributes.to_a.to_sentence} " <<
View
2  lib/shoulda/matchers/active_record/serialize_matcher.rb
@@ -1,7 +1,6 @@
module Shoulda # :nodoc:
module Matchers
module ActiveRecord # :nodoc:
-
# Ensure that the field becomes serialized.
#
# Options:
@@ -10,6 +9,7 @@ module ActiveRecord # :nodoc:
# Example:
# it { should serialize(:details) }
# it { should serialize(:details).as(Hash) }
+ # it { should serialize(:details).as_instance_of(ExampleSerializer) }
#
def serialize(name)
SerializeMatcher.new(name)
View
4 lib/shoulda/matchers/assertion_error.rb
@@ -3,11 +3,11 @@ module Matchers
if Gem.ruby_version >= Gem::Version.new('1.8') && Gem.ruby_version < Gem::Version.new('1.9')
require 'test/unit'
AssertionError = Test::Unit::AssertionFailedError
- elsif Gem.ruby_version >= Gem::Version.new("1.9")
+ elsif Gem.ruby_version >= Gem::Version.new('1.9')
require 'minitest/unit'
AssertionError = MiniTest::Assertion
else
- raise "No unit test library available"
+ raise 'No unit test library available'
end
end
end
View
35 spec/shoulda/matchers/action_controller/assign_to_matcher_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe Shoulda::Matchers::ActionController::AssignToMatcher do
- it "should include the actual class in the failure message" do
+ it 'includes the actual class in the failure message' do
define_class(:WrongClass) do
def to_s
'wrong class'
@@ -15,48 +15,51 @@ def to_s
matcher.failure_message.should =~ /but got wrong class \(WrongClass\)$/
end
- context "a controller that assigns to an instance variable" do
- let(:controller) { build_response { @var = 'value' } }
-
- it "should accept assigning to that variable" do
+ context 'a controller that assigns to an instance variable' do
+ it 'accepts assigning to that variable' do
controller.should assign_to(:var)
end
- it "should accept assigning to that variable with the correct class" do
+ it 'accepts assigning to that variable with the correct class' do
controller.should assign_to(:var).with_kind_of(String)
end
- it "should reject assigning to that variable with another class" do
+ it 'rejects assigning to that variable with another class' do
controller.should_not assign_to(:var).with_kind_of(Fixnum)
end
- it "should accept assigning the correct value to that variable" do
+ it 'accepts assigning the correct value to that variable' do
controller.should assign_to(:var).with('value')
end
- it "should reject assigning another value to that variable" do
+ it 'rejects assigning another value to that variable' do
controller.should_not assign_to(:var).with('other')
end
- it "should reject assigning to another variable" do
+ it 'rejects assigning to another variable' do
controller.should_not assign_to(:other)
end
- it "should accept assigning to the same value in the test context" do
+ it 'accepts assigning to the same value in the test context' do
expected = 'value'
controller.should assign_to(:var).in_context(self).with { expected }
end
- it "should reject assigning to the another value in the test context" do
+ it 'rejects assigning to the another value in the test context' do
expected = 'other'
controller.should_not assign_to(:var).in_context(self).with { expected }
end
- end
- context "a controller that assigns a nil value to an instance variable" do
- let(:controller) { build_response { @var = nil } }
+ def controller
+ build_response { @var = 'value' }
+ end
+ end
- it "should accept assigning to that variable" do
+ context 'a controller that assigns a nil value to an instance variable' do
+ it 'accepts assigning to that variable' do
+ controller = build_response do
+ @var = nil
+ end
controller.should assign_to(:var)
end
end
View
28 spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb
@@ -1,20 +1,22 @@
require 'spec_helper'
describe Shoulda::Matchers::ActionController::FilterParamMatcher do
- context "given parameter filters" do
- before do
- Rails.application.config.filter_parameters = [:secret]
- end
+ it 'accepts filtering a filtered parameter' do
+ filter(:secret)
- it "should accept filtering that parameter" do
- nil.should filter_param(:secret)
- end
+ nil.should filter_param(:secret)
+ end
+
+ it 'rejects filtering an unfiltered parameter' do
+ filter(:secret)
+ matcher = filter_param(:other)
+
+ matcher.matches?(nil).should be_false
+
+ matcher.failure_message.should =~ /Expected other to be filtered.*secret/
+ end
- it "should reject filtering another parameter" do
- matcher = filter_param(:other)
- matcher.matches?(nil).should be_false
- matcher.failure_message.should include("Expected other to be filtered")
- matcher.failure_message.should =~ /secret/
- end
+ def filter(param)
+ Rails.application.config.filter_parameters = [param]
end
end
View
36 spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb
@@ -1,40 +1,42 @@
require 'spec_helper'
describe Shoulda::Matchers::ActionController::RedirectToMatcher do
- context "a controller that redirects" do
- let(:controller) do
- build_response { redirect_to '/some/url' }
+ context 'a controller that redirects' do
+ it 'accepts redirecting to that url' do
+ controller_redirecting_to('/some/url').should redirect_to('/some/url')
end
- it "accepts redirecting to that url" do
- controller.should redirect_to('/some/url')
+ it 'rejects redirecting to a different url' do
+ controller_redirecting_to('/some/url').should_not
+ redirect_to('/some/other/url')
end
- it "rejects redirecting to a different url" do
- controller.should_not redirect_to('/some/other/url')
+ it 'accepts redirecting to that url in a block' do
+ controller_redirecting_to('/some/url').should
+ redirect_to('somewhere') { '/some/url' }
end
- it "accepts redirecting to that url in a block" do
- controller.should redirect_to('somewhere') { '/some/url' }
+ it 'rejects redirecting to a different url in a block' do
+ controller_redirecting_to('/some/url').should_not
+ redirect_to('somewhere else') { '/some/other/url' }
end
- it "rejects redirecting to a different url in a block" do
- controller.should_not redirect_to('somewhere else') { '/some/other/url' }
+ def controller_redirecting_to(url)
+ build_response { redirect_to url }
end
end
- context "a controller that doesn't redirect" do
- let(:controller) do
- build_response { render :text => 'hello' }
- end
+ context 'a controller that does not redirect' do
+ it 'rejects redirecting to a url' do
+ controller = build_response { render :text => 'hello' }
- it "rejects redirecting to a url" do
controller.should_not redirect_to('/some/url')
end
end
- it "provides the correct description when provided a block" do
+ it 'provides the correct description when provided a block' do
matcher = redirect_to('somewhere else') { '/some/other/url' }
+
matcher.description.should == 'redirect to somewhere else'
end
end
View
71 spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb
@@ -3,67 +3,76 @@
describe Shoulda::Matchers::ActionController::RenderTemplateMatcher do
include ActionController::TemplateAssertions
- context "a controller that renders a template" do
- let(:controller) { build_response(:action => 'show') { render } }
+ context 'a controller that renders a template' do
+ it 'accepts rendering that template' do
+ controller_with_show.should render_template(:show)
+ end
- it "accepts rendering that template" do
- controller.should render_template(:show)
+ it 'rejects rendering a different template' do
+ controller_with_show.should_not render_template(:index)
end
- it "rejects rendering a different template" do
- controller.should_not render_template(:index)
+ it 'accepts rendering that template in the given context' do
+ controller_with_show.should render_template(:show).in_context(self)
end
- it "accepts rendering that template in the given context" do
- controller.should render_template(:show).in_context(self)
+ it 'rejects rendering a different template in the given context' do
+ controller_with_show.should_not render_template(:index).in_context(self)
end
- it "rejects rendering a different template in the given context" do
- controller.should_not render_template(:index).in_context(self)
+ def controller_with_show
+ build_response(:action => 'show') { render }
end
end
- context "a controller that renders a partial" do
- let(:controller) { build_response(:partial => '_customer') { render :partial => 'customer' } }
+ context 'a controller that renders a partial' do
+ it 'accepts rendering that partial' do
+ controller_with_customer_partial.should
+ render_template(:partial => '_customer')
+ end
- it "accepts rendering that partial" do
- controller.should render_template(:partial => '_customer')
+ it 'rejects rendering a different template' do
+ controller_with_customer_partial.should_not
+ render_template(:partial => '_client')
end
- it "rejects rendering a different template" do
- controller.should_not render_template(:partial => '_client')
+ it 'accepts rendering that template in the given context' do
+ controller_with_customer_partial.should
+ render_template(:partial => '_customer').in_context(self)
end
- it "accepts rendering that template in the given context" do
- controller.should render_template(:partial => '_customer').in_context(self)
+ it 'rejects rendering a different template in the given context' do
+ controller_with_customer_partial.should_not
+ render_template(:partial => '_client').in_context(self)
end
- it "rejects rendering a different template in the given context" do
- controller.should_not render_template(:partial => '_client').in_context(self)
+ def controller_with_customer_partial
+ build_response(:partial => '_customer') { render :partial => 'customer' }
end
end
- context "a controller that doesn't render partials" do
- let(:controller) { build_response(:action => 'show') { render } }
+ context 'a controller that does not render partials' do
+ it 'accepts not rendering a partial' do
+ controller = build_response(:action => 'show') { render }
- it "should not render a partial" do
controller.should render_template(:partial => false)
end
end
- context "a controller that renders a partial several times" do
- let(:controller) { build_response(:partial => '_customer') { render :partial => 'customer', :collection => [1,2] } }
+ context 'a controller that renders a partial several times' do
+ it 'accepts rendering that partial twice' do
+ controller = build_response(:partial => '_customer') do
+ render :partial => 'customer', :collection => [1,2]
+ end
- it "accepts rendering that partial twice" do
controller.should render_template(:partial => '_customer', :count => 2)
end
end
- context "a controller that doesn't render a template" do
- let(:controller) { build_response { render :nothing => true } }
-
- it "rejects rendering a template" do
- controller.should_not render_template(:show)
+ context 'a controller that does not render a template' do
+ it 'rejects rendering a template' do
+ build_response { render :nothing => true }.should_not
+ render_template(:show)
end
end
end
View
53 spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb
@@ -3,53 +3,56 @@
describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher do
include ActionController::TemplateAssertions
- context "a controller that renders with a layout" do
- let(:controller) { build_response { render :layout => 'wide' } }
-
- before do
- create_view('layouts/wide.html.erb', 'some content, <%= yield %>')
+ context 'a controller that renders with a layout' do
+ it 'accepts rendering with any layout' do
+ controller_with_wide_layout.should render_with_layout
end
- it "should accept rendering with any layout" do
- controller.should render_with_layout
+ it 'accepts rendering with that layout' do
+ controller_with_wide_layout.should render_with_layout(:wide)
end
- it "should accept rendering with that layout" do
- controller.should render_with_layout(:wide)
+ it 'rejects rendering with another layout' do
+ controller_with_wide_layout.should_not render_with_layout(:other)
end
- it "should reject rendering with another layout" do
- controller.should_not render_with_layout(:other)
+ def controller_with_wide_layout
+ create_view('layouts/wide.html.erb', 'some content, <%= yield %>')
+ build_response { render :layout => 'wide' }
end
end
- context "a controller that renders without a layout" do
- let(:controller) { build_response { render :layout => false } }
+ context 'a controller that renders without a layout' do
- it "should reject rendering with a layout" do
- controller.should_not render_with_layout
+ it 'rejects rendering with a layout' do
+ controller_without_layout = build_response { render :layout => false }
+
+ controller_without_layout.should_not render_with_layout
end
end
- context "a controller that renders a partial" do
- let(:controller) { build_response { render :partial => 'partial' } }
+ context 'a controller that renders a partial' do
+ it 'rejects rendering with a layout' do
+ controller_with_partial = build_response { render :partial => 'partial' }
- it "should reject rendering with a layout" do
- controller.should_not render_with_layout
+ controller_with_partial.should_not render_with_layout
end
end
- context "given a context with layouts" do
- let(:layout) { 'happy' }
- let(:controller) { build_response { render :layout => false } }
+ context 'given a context with layouts' do
+ it 'accepts that layout in that context' do
+ set_in_context_layout('happy')
+
+ controller_without_layout.should render_with_layout('happy').in_context(self)
+ end
- before do
+ def set_in_context_layout(layout)
@layouts = Hash.new(0)
@layouts[layout] = 1
end
- it "should accept that layout in that context" do
- controller.should render_with_layout(layout).in_context(self)
+ def controller_without_layout
+ build_response { render :layout => false }
end
end
end
View
37 spec/shoulda/matchers/action_controller/respond_with_content_type_matcher_spec.rb
@@ -1,28 +1,31 @@
require 'spec_helper'
describe Shoulda::Matchers::ActionController::RespondWithContentTypeMatcher do
- context "a controller responding with content type :xml" do
- let(:controller) { build_response { render :xml => { :user => "thoughtbot" }.to_xml } }
+ it 'generates the correct description' do
+ expected = 'respond with content type of application/xml'
- it "should accept responding with content type :xml" do
- controller.should respond_with_content_type(:xml)
- end
+ respond_with_content_type(:xml).description.should == expected
+ end
- it "should accept responding with content type 'application/xml'" do
- controller.should respond_with_content_type('application/xml')
- end
+ it 'accepts responding with content type as symbol' do
+ xml_controller.should respond_with_content_type(:xml)
+ end
- it "should accept responding with content type /xml/" do
- controller.should respond_with_content_type(/xml/)
- end
+ it 'accepts responding with qualified MIME-style content type' do
+ xml_controller.should respond_with_content_type('application/xml')
+ end
- it "should reject responding with another content type" do
- controller.should_not respond_with_content_type(:json)
- end
+ it 'accepts responding with a regex matching the content type' do
+ xml_controller.should respond_with_content_type(/xml/)
end
- it "should generate the correct test name" do
- respond_with_content_type(:xml).description.
- should == "respond with content type of application/xml"
+ it 'rejects responding with another content type' do
+ xml_controller.should_not respond_with_content_type(:json)
+ end
+
+ def xml_controller
+ build_response do
+ render :xml => { :user => 'thoughtbot' }.to_xml
+ end
end
end
View
88 spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb
@@ -1,83 +1,31 @@
require 'spec_helper'
describe Shoulda::Matchers::ActionController::RespondWithMatcher do
- context "a controller responding with success" do
- let(:controller) { build_response { render :text => "text", :status => 200 } }
+ statuses = { :success => 200, :redirect => 301, :missing => 404, :error => 500,
+ :not_implemented => 501 }
- it "should accept responding with 200" do
- controller.should respond_with(200)
- end
-
- it "should accept responding with :success" do
- controller.should respond_with(:success)
- end
-
- it "should reject responding with another status" do
- controller.should_not respond_with(:error)
- end
- end
-
- context "a controller responding with redirect" do
- let(:controller) { build_response { render :text => "text", :status => 301 } }
-
- it "should accept responding with 301" do
- controller.should respond_with(301)
- end
-
- it "should accept responding with :redirect" do
- controller.should respond_with(:redirect)
- end
-
- it "should reject responding with another status" do
- controller.should_not respond_with(:error)
- end
- end
-
- context "a controller responding with missing" do
- let(:controller) { build_response { render :text => "text", :status => 404 } }
+ statuses.each do |human_name, numeric_code|
+ context "a controller responding with #{human_name}" do
+ it 'accepts responding with a numeric response code' do
+ controller_with_status(numeric_code).should respond_with(numeric_code)
+ end
- it "should accept responding with 404" do
- controller.should respond_with(404)
- end
+ it 'accepts responding with a symbol response code' do
+ controller_with_status(numeric_code).should respond_with(human_name)
+ end
- it "should accept responding with :missing" do
- controller.should respond_with(:missing)
- end
+ it 'rejects responding with another status' do
+ another_status = statuses.except(human_name).keys.first
- it "should reject responding with another status" do
- controller.should_not respond_with(:success)
+ controller_with_status(numeric_code).should_not
+ respond_with(another_status)
+ end
end
end
- context "a controller responding with error" do
- let(:controller) { build_response { render :text => "text", :status => 500 } }
-
- it "should accept responding with 500" do
- controller.should respond_with(500)
- end
-
- it "should accept responding with :error" do
- controller.should respond_with(:error)
- end
-
- it "should reject responding with another status" do
- controller.should_not respond_with(:success)
- end
- end
-
- context "a controller responding with not implemented" do
- let(:controller) { build_response { render :text => "text", :status => 501 } }
-
- it "should accept responding with 501" do
- controller.should respond_with(501)
- end
-
- it "should accept responding with :not_implemented" do
- controller.should respond_with(:not_implemented)
- end
-
- it "should reject responding with another status" do
- controller.should_not respond_with(:success)
+ def controller_with_status(status)
+ build_response do
+ render :text => 'text', :status => status
end
end
end
View
56 spec/shoulda/matchers/action_controller/route_matcher_spec.rb
@@ -1,65 +1,65 @@
require 'spec_helper'
describe Shoulda::Matchers::ActionController::RouteMatcher do
- context "given a controller with a defined glob url" do
- let(:controller) { define_controller('Examples').new }
+ context 'given a controller with a defined glob url' do
+ it 'accepts glob route' do
+ controller = define_controller('Examples').new
- before do
define_routes do
match 'examples/*id', :to => 'examples#example'
end
- end
- it "should accept glob route" do
controller.should route(:get, '/examples/foo/bar').
to(:action => 'example', :id => 'foo/bar')
end
end
- context "given a controller with a defined route" do
- let!(:controller) { define_controller('Examples').new }
-
- before do
- define_routes do
- match 'examples/:id', :to => 'examples#example'
- end
- end
+ context 'given a controller with a defined route' do
- it "should accept routing the correct path to the correct parameters" do
- controller.should route(:get, '/examples/1').
+ it 'accepts routing the correct path to the correct parameters' do
+ route_examples_to_examples.should route(:get, '/examples/1').
to(:action => 'example', :id => '1')
end
- it "should accept a symbol controller" do
+ it 'accepts a symbol controller' do
+ route_examples_to_examples
Object.new.should route(:get, '/examples/1').
- to(:controller => :examples,
- :action => 'example',
- :id => '1')
+ to(:controller => :examples, :action => 'example', :id => '1')
end
- it "should accept a symbol action" do
- controller.should route(:get, '/examples/1').
+ it 'accepts a symbol action' do
+ route_examples_to_examples.should route(:get, '/examples/1').
to(:action => :example, :id => '1')
end
- it "should accept a non-string parameter" do
- controller.should route(:get, '/examples/1').
+ it 'accepts a non-string parameter' do
+ route_examples_to_examples.should route(:get, '/examples/1').
to(:action => 'example', :id => 1)
end
- it "should reject an undefined route" do
- controller.should_not route(:get, '/bad_route').to(:var => 'value')
+ it 'rejects an undefined route' do
+ route_examples_to_examples.should_not
+ route(:get, '/bad_route').to(:var => 'value')
end
- it "should reject a route for another controller" do
+ it 'rejects a route for another controller' do
+ route_examples_to_examples
other = define_controller('Other').new
other.should_not route(:get, '/examples/1').
to(:action => 'example', :id => '1')
end
- it "should reject a route for different parameters" do
- controller.should_not route(:get, '/examples/1').
+ it 'rejects a route for different parameters' do
+ route_examples_to_examples.should_not route(:get, '/examples/1').
to(:action => 'other', :id => '1')
end
+
+ def route_examples_to_examples
+ define_routes do
+ get 'examples/:id', :to => 'examples#example'
+ end
+
+ define_controller('Examples').new
+ end
end
end
View
53 spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
@@ -1,46 +1,51 @@
require 'spec_helper'
describe Shoulda::Matchers::ActionController::SetSessionMatcher do
- context "a controller that sets a session variable" do
- let(:controller) do
- build_response do
- session[:var] = 'value'
- session[:false_var] = false
- end
+ context 'a controller that sets a session variable' do
+ it 'accepts assigning to that variable' do
+ controller_with_session(:var => 'hi').should set_session(:var)
end
- it "should accept assigning to that variable" do
- controller.should set_session(:var)
+ it 'accepts assigning the correct value to that variable' do
+ controller_with_session(:var => 'hi').should set_session(:var).to('hi')
end
- it "should accept assigning the correct value to that variable" do
- controller.should set_session(:var).to('value')
+ it 'rejects assigning another value to that variable' do
+ controller_with_session(:var => 'hi').should_not set_session(:var).to('other')
end
- it "should reject assigning another value to that variable" do
- controller.should_not set_session(:var).to('other')
+ it 'rejects assigning to another variable' do
+ controller_with_session(:var => 'hi').should_not set_session(:other)
end
- it "should reject assigning to another variable" do
- controller.should_not set_session(:other)
+ it 'accepts assigning nil to another variable' do
+ controller_with_session(:var => 'hi').should set_session(:other).to(nil)
end
- it "should accept assigning nil to another variable" do
- controller.should set_session(:other).to(nil)
+ it 'accepts assigning false to that variable' do
+ controller_with_session(:var => false).should set_session(:var).to(false)
end
- it "should accept assigning false to that variable" do
- controller.should set_session(:false_var).to(false)
- end
-
- it "should accept assigning to the same value in the test context" do
+ it 'accepts assigning to the same value in the test context' do
expected = 'value'
- controller.should set_session(:var).in_context(self).to { expected }
+
+ controller_with_session(:var => expected).should
+ set_session(:var).in_context(self).to { expected }
end
- it "should reject assigning to the another value in the test context" do
+ it 'rejects assigning to the another value in the test context' do
expected = 'other'
- controller.should_not set_session(:var).in_context(self).to { expected }
+
+ controller_with_session(:var => 'unexpected').should_not
+ set_session(:var).in_context(self).to { expected }
+ end
+
+ def controller_with_session(session_hash)
+ build_response do
+ session_hash.each do |key, value|
+ session[key] = value
+ end
+ end
end
end
end
View
157 spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb
@@ -1,130 +1,155 @@
require 'spec_helper'
describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do
- it "should fail with unmatchable to" do
- expect{
+ it 'fails with unmatchable #to' do
+ expect {
set_the_flash.to(1).should
- }.to raise_error("cannot match against 1")
+ }.to raise_error('cannot match against 1')
end
- context "a controller that sets a flash message" do
- let(:controller) { build_response { flash[:notice] = 'value' } }
-
- it "should accept setting any flash message" do
- controller.should set_the_flash
+ context 'a controller that sets a flash message' do
+ it 'accepts setting any flash message' do
+ controller_with_flash(:notice => 'hi').should set_the_flash
end
- it "should accept setting the exact flash message" do
- controller.should set_the_flash.to('value')
+ it 'accepts setting the exact flash message' do
+ controller_with_flash(:notice => 'hi').should set_the_flash.to('hi')
end
- it "should accept setting a matched flash message" do
- controller.should set_the_flash.to(/value/)
+ it 'accepts setting a matched flash message' do
+ controller_with_flash(:notice => 'hello').should set_the_flash.to(/he/)
end
- it "should reject setting a different flash message" do
- controller.should_not set_the_flash.to('other')
+ it 'rejects setting a different flash message' do
+ controller_with_flash(:notice => 'hi').should_not
+ set_the_flash.to('other')
end
- it "should reject setting a different pattern" do
- controller.should_not set_the_flash.to(/other/)
+ it 'rejects setting a different pattern' do
+ controller_with_flash(:notice => 'hi').should_not
+ set_the_flash.to(/other/)
end
end
- context "a controller that sets a flash.now message" do
- let(:controller) { build_response { flash.now[:notice] = 'value' } }
-
- it "should reject setting any flash message" do
- controller.should_not set_the_flash
+ context 'a controller that sets a flash.now message' do
+ it 'rejects setting any flash message' do
+ controller_with_flash_now.should_not set_the_flash
end
- it "should accept setting any flash.now message" do
- controller.should set_the_flash.now
+ it 'accepts setting any flash.now message' do
+ controller_with_flash_now.should set_the_flash.now
end
- it "should accept setting the exact flash.now message" do
- controller.should set_the_flash.to('value').now
+ it 'accepts setting the exact flash.now message' do
+ controller_with_flash_now(:notice => 'hi').should
+ set_the_flash.now.to('hi')
end
- it "should accept setting a matched flash.now message" do
- controller.should set_the_flash.to(/value/).now
+ it 'accepts setting a matched flash.now message' do
+ controller_with_flash_now(:notice => 'flasher').should
+ set_the_flash.now.to(/lash/)
end
- it "should reject setting a different flash.now message" do
- controller.should_not set_the_flash.to('other').now
+ it 'rejects setting a different flash.now message' do
+ controller_with_flash_now(:notice => 'hi').should_not
+ set_the_flash.now.to('other')
end
- it "should reject setting a different flash.now pattern" do
- controller.should_not set_the_flash.to(/other/).now
+ it 'rejects setting a different flash.now pattern' do
+ controller_with_flash_now(:notice => 'hi').should_not
+ set_the_flash.now.to(/other/)
end
end
- context "a controller that sets a flash message of notice and alert" do
- let(:controller) do
- build_response do
- flash[:notice] = 'value'
- flash[:alert] = 'other'
- end
- end
-
- it "should accept flash message of notice" do
- controller.should set_the_flash[:notice]
- end
+ context 'a controller that sets flash messages for multiple keys' do
+ it 'accepts flash message for either key' do
+ controller = controller_with_flash(:notice => 'one', :alert => 'two')
- it "should accept flash message of alert" do
controller.should set_the_flash[:notice]
+ controller.should set_the_flash[:alert]
end
- it "should reject flash message of warning" do
- controller.should_not set_the_flash[:warning]
+ it 'rejects a flash message that is not one of the set keys' do
+ controller_with_flash(:notice => 'one', :alert => 'two').should_not
+ set_the_flash[:warning]
end
- it "should accept exact flash message of notice" do
- controller.should set_the_flash[:notice].to('value')
+ it 'accepts exact flash message of notice' do
+ controller_with_flash(:notice => 'one', :alert => 'two').should
+ set_the_flash[:notice].to('one')
end
- it "should accept setting a matched flash message of notice" do
- controller.should set_the_flash[:notice].to(/value/)
+ it 'accepts setting a matched flash message of notice' do
+ controller_with_flash(:notice => 'one', :alert => 'two').should
+ set_the_flash[:notice].to(/on/)
end
- it "should reject setting a different flash message of notice" do
- controller.should_not set_the_flash[:notice].to('other')
+ it 'rejects setting a different flash message of notice' do
+ controller_with_flash(:notice => 'one', :alert => 'two').should_not
+ set_the_flash[:notice].to('other')
end
- it "should reject setting a different pattern" do
- controller.should_not set_the_flash[:notice].to(/other/)
+ it 'rejects setting a different pattern' do
+ controller_with_flash(:notice => 'one', :alert => 'two').should_not
+ set_the_flash[:notice].to(/other/)
end
end
- context "a controller that sets multiple flash messages" do
- let(:controller) do
- build_response do
+ context 'a controller that sets flash and flash.now' do
+ it 'accepts setting any flash.now message' do
+ controller = build_response do
flash.now[:notice] = 'value'
flash[:success] = 'great job'
end
- end
- it "should accept setting any flash.now message" do
controller.should set_the_flash.now
controller.should set_the_flash
end
- it "should accept setting a matched flash.now message" do
- controller.should set_the_flash.to(/value/).now
+ it 'accepts setting a matched flash.now message' do
+ controller = build_response do
+ flash.now[:notice] = 'value'
+ flash[:success] = 'great job'
+ end
+
+ controller.should set_the_flash.now.to(/value/)
controller.should set_the_flash.to(/great/)
end
- it "should reject setting a different flash.now message" do
- controller.should_not set_the_flash.to('other').now
+ it 'rejects setting a different flash.now message' do
+ controller = build_response do
+ flash.now[:notice] = 'value'
+ flash[:success] = 'great job'
+ end
+
+ controller.should_not set_the_flash.now.to('other')
controller.should_not set_the_flash.to('other')
end
end
- context "a controller that doesn't set a flash message" do
- let(:controller) { build_response }
+ context 'a controller that does not set a flash message' do
+ it 'rejects setting any flash message' do
+ controller_with_no_flashes.should_not set_the_flash
+ end
+ end
+
+ def controller_with_no_flashes
+ build_response
+ end
- it "should reject setting any flash message" do
- controller.should_not set_the_flash
+ def controller_with_flash(flash_hash)
+ build_response do
+ flash_hash.each do |key, value|
+ flash[key] = value
+ end
+ end
+ end
+
+ def controller_with_flash_now(flash_hash = { :notice => 'hi' })
+ build_response do
+ flash_hash.each do |key, value|
+ flash.now[key] = value
+ end
end
end
end
View
199 spec/shoulda/matchers/action_mailer/have_sent_email_spec.rb
@@ -1,22 +1,23 @@
require 'spec_helper'
describe Shoulda::Matchers::ActionMailer::HaveSentEmailMatcher do
- subject { Shoulda::Matchers::ActionMailer::HaveSentEmailMatcher.new(self) }
+ subject { described_class.new(self) }
+ after { ::ActionMailer::Base.deliveries.clear }
def add_mail_to_deliveries(params = nil)
::ActionMailer::Base.deliveries << Mailer.the_email(params)
end
- context "testing with instance variables with no multipart" do
+ context 'testing with instance variables with no multipart' do
let(:info) do
{
- :from => "do-not-reply@example.com",
- :reply_to => "reply-to-me@example.com",
- :to => "myself@me.com",
- :cc => ["you@you.com", "joe@bob.com", "hello@goodbye.com"],
- :bcc => ["test@example.com", "sam@bob.com", "goodbye@hello.com"],
- :subject => "This is spam",
- :body => "Every email is spam."
+ :from => 'do-not-reply@example.com',
+ :reply_to => 'reply-to-me@example.com',
+ :to => 'myself@me.com',
+ :cc => ['you@you.com', 'joe@bob.com', 'hello@goodbye.com'],
+ :bcc => ['test@example.com', 'sam@bob.com', 'goodbye@hello.com'],
+ :subject => 'This is spam',
+ :body => 'Every email is spam.'
}
end
@@ -29,55 +30,53 @@ def the_email(params)
add_mail_to_deliveries(info)
end
- after { ::ActionMailer::Base.deliveries.clear }
-
- it "should send an e-mail based on subject" do
+ it 'sends an e-mail based on subject' do
should have_sent_email.with_subject{ info[:subject] }
end
- it "should send an e-mail based on recipient" do
+ it 'sends an e-mail based on recipient' do
should have_sent_email.to(nil) { info[:to] }
end
- it "should send an e-mail based on sender" do
+ it 'sends an e-mail based on sender' do
should have_sent_email.from{ info[:from] }
end
- it "should send an e-email based on reply_to" do
+ it 'sends an e-email based on reply_to' do
should have_sent_email.reply_to { info[:reply_to] }
end
- it "should send an e-mail based on cc" do
+ it 'sends an e-mail based on cc' do
should have_sent_email.cc{ info[:cc][0] }
end
- it "should send an e-mail based on cc list" do
+ it 'sends an e-mail based on cc list' do
should have_sent_email.with_cc{ info[:cc] }
end
- it "should send an e-mail based on bcc" do
+ it 'sends an e-mail based on bcc' do
should have_sent_email.bcc{ info[:bcc][0] }
end
- it "should send an e-mail based on bcc list" do
+ it 'sends an e-mail based on bcc list' do
should have_sent_email.with_bcc{ info[:bcc] }
end
- it "should send an e-mail based on body" do
+ it 'sends an e-mail based on body' do
should have_sent_email.with_body{ info[:body] }
end
end
- context "testing with instance variables with multiple parts" do
+ context 'testing with instance variables with multiple parts' do
let(:info) do
{
- :from => "do-not-reply@example.com",
- :to => "myself@me.com",
- :cc => ["you@you.com", "joe@bob.com", "hello@goodbye.com"],
- :bcc => ["test@example.com", "sam@bob.com", "goodbye@hello.com"],
- :subject => "This is spam",
- :text => "Every email is spam.",
- :html => "<h1>HTML is spam.</h1><p>Notably.</p>"
+ :from => 'do-not-reply@example.com',
+ :to => 'myself@me.com',
+ :cc => ['you@you.com', 'joe@bob.com', 'hello@goodbye.com'],
+ :bcc => ['test@example.com', 'sam@bob.com', 'goodbye@hello.com'],
+ :subject => 'This is spam',
+ :text => 'Every email is spam.',
+ :html => '<h1>HTML is spam.</h1><p>Notably.</p>'
}
end
@@ -93,170 +92,164 @@ def the_email(params)
add_mail_to_deliveries(info)
end
- after { ::ActionMailer::Base.deliveries.clear }
-
- it "should send emails with text and html parts" do
+ it 'sends emails with text and html parts' do
should have_sent_email.with_part('text/plain') { info[:text] }.with_part('text/html') { info[:html] }
end
- it "should have the block override the method argument" do
+ it 'should have the block override the method argument' do
should have_sent_email.with_part('text/plain', 'foo') { info[:text] }.with_part('text/html', /bar/) { info[:html] }
end
end
- context "an email without multiple parts" do
+ context 'an email without multiple parts' do
before do
define_mailer :mailer, [:the_email] do
def the_email(params)
- mail :from => "do-not-reply@example.com",
- :to => "myself@me.com",
- :subject => "This is spam",
- :cc => ["you@you.com", "joe@bob.com", "hello@goodbye.com"],
- :bcc => ["test@example.com", "sam@bob.com", "goodbye@hello.com"],
- :body => "Every email is spam."
+ mail :from => 'do-not-reply@example.com',
+ :to => 'myself@me.com',
+ :subject => 'This is spam',
+ :cc => ['you@you.com', 'joe@bob.com', 'hello@goodbye.com'],
+ :bcc => ['test@example.com', 'sam@bob.com', 'goodbye@hello.com'],
+ :body => 'Every email is spam.'
end
end
add_mail_to_deliveries
end
- after { ::ActionMailer::Base.deliveries.clear }
-
- it "accepts sent-email when it is not multipart" do
+ it 'accepts sent-email when it is not multipart' do
should_not have_sent_email.multipart
matcher = have_sent_email.multipart(true)
matcher.matches?(Mailer.the_email(nil))
matcher.failure_message.should =~ /Expected sent email being multipart/
end
- it "matches the body with a regexp" do
+ it 'matches the body with a regexp' do
should have_sent_email.with_body(/email is spam/)
end
- it "matches the body with a string" do
- should have_sent_email.with_body("Every email is spam.")
- should_not have_sent_email.with_body("emails is")
+ it 'matches the body with a string' do
+ should have_sent_email.with_body('Every email is spam.')
+ should_not have_sent_email.with_body('emails is')
end
end
- context "an email with both a text/plain and text/html part" do
+ context 'an email with both a text/plain and text/html part' do
before do
define_mailer :mailer, [:the_email] do
def the_email(params)
- mail :from => "do-not-reply@example.com",
- :to => "myself@me.com",
- :cc => ["you@you.com", "joe@bob.com", "hello@goodbye.com"],
- :bcc => ["test@example.com", "sam@bob.com", "goodbye@hello.com"],
- :subject => "This is spam" do |format|
-
- format.text { render :text => "Every email is spam." }
- format.html { render :text => "<h1>HTML is spam.</h1><p>Notably.</p>" }
+ mail :from => 'do-not-reply@example.com',
+ :to => 'myself@me.com',
+ :cc => ['you@you.com', 'joe@bob.com', 'hello@goodbye.com'],
+ :bcc => ['test@example.com', 'sam@bob.com', 'goodbye@hello.com'],
+ :subject => 'This is spam' do |format|
+
+ format.text { render :text => 'Every email is spam.' }
+ format.html { render :text => '<h1>HTML is spam.</h1><p>Notably.</p>' }
end
end
end
add_mail_to_deliveries
end
- after { ::ActionMailer::Base.deliveries.clear }
-
- it "accepts sent e-mail based on the subject" do
+ it 'accepts sent e-mail based on the subject' do
should have_sent_email.with_subject(/is spam$/)
matcher = have_sent_email.with_subject(/totally safe/)
matcher.matches?(nil)
matcher.failure_message.should =~ /Expected sent email with subject/
end
- it "accepts sent e-mail based on a string sender" do
+ it 'accepts sent e-mail based on a string sender' do
should have_sent_email.from('do-not-reply@example.com')
matcher = have_sent_email.from('you@example.com')
matcher.matches?(nil)
matcher.failure_message.should =~ /Expected sent email from/
end
- it "accepts sent e-mail based on a regexp sender" do
+ it 'accepts sent e-mail based on a regexp sender' do
should have_sent_email.from(/@example\.com/)
matcher = have_sent_email.from(/you@/)
matcher.matches?(nil)
matcher.failure_message.should =~ /Expected sent email from/
end
- it "accepts sent e-mail based on the body" do
+ it