Ensure that `should` is on the same line as the expectation

This commit is contained in:
Chris Bandy 2013-03-15 01:32:53 -05:00 committed by Melissa Xie
parent 408174f2c5
commit 4dace352f8
25 changed files with 339 additions and 318 deletions

View File

@ -7,18 +7,18 @@ describe Shoulda::Matchers::ActionController::RedirectToMatcher do
end
it 'rejects redirecting to a different url' do
controller_redirecting_to('/some/url').should_not
redirect_to('/some/other/url')
controller_redirecting_to('/some/url').
should_not redirect_to('/some/other/url')
end
it 'accepts redirecting to that url in a block' do
controller_redirecting_to('/some/url').should
redirect_to('somewhere') { '/some/url' }
controller_redirecting_to('/some/url').
should redirect_to('somewhere') { '/some/url' }
end
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' }
controller_redirecting_to('/some/url').
should_not redirect_to('somewhere else') { '/some/other/url' }
end
def controller_redirecting_to(url)

View File

@ -27,23 +27,23 @@ describe Shoulda::Matchers::ActionController::RenderTemplateMatcher do
context 'a controller that renders a partial' do
it 'accepts rendering that partial' do
controller_with_customer_partial.should
render_template(:partial => '_customer')
controller_with_customer_partial.
should render_template(:partial => '_customer')
end
it 'rejects rendering a different template' do
controller_with_customer_partial.should_not
render_template(:partial => '_client')
controller_with_customer_partial.
should_not render_template(:partial => '_client')
end
it 'accepts rendering that template in the given context' do
controller_with_customer_partial.should
render_template(:partial => '_customer').in_context(self)
controller_with_customer_partial.
should render_template(:partial => '_customer').in_context(self)
end
it 'rejects rendering a different template in the given context' do
controller_with_customer_partial.should_not
render_template(:partial => '_client').in_context(self)
controller_with_customer_partial.
should_not render_template(:partial => '_client').in_context(self)
end
def controller_with_customer_partial
@ -71,8 +71,8 @@ describe Shoulda::Matchers::ActionController::RenderTemplateMatcher do
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)
build_response { render :nothing => true }.
should_not render_template(:show)
end
end
end

View File

@ -17,8 +17,8 @@ describe Shoulda::Matchers::ActionController::RespondWithMatcher do
it 'rejects responding with another status' do
another_status = statuses.except(human_name).keys.first
controller_with_status(numeric_code).should_not
respond_with(another_status)
controller_with_status(numeric_code).
should_not respond_with(another_status)
end
end
end

View File

@ -38,8 +38,8 @@ describe Shoulda::Matchers::ActionController::RouteMatcher do
end
it 'rejects an undefined route' do
route_examples_to_examples.should_not
route(:get, '/bad_route').to(:var => 'value')
route_examples_to_examples.
should_not route(:get, '/bad_route').to(:var => 'value')
end
it 'rejects a route for another controller' do

View File

@ -29,15 +29,15 @@ describe Shoulda::Matchers::ActionController::SetSessionMatcher do
it 'accepts assigning to the same value in the test context' do
expected = 'value'
controller_with_session(:var => expected).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 'rejects assigning to the another value in the test context' do
expected = 'other'
controller_with_session(:var => 'unexpected').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)

View File

@ -2,9 +2,7 @@ require 'spec_helper'
describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do
it 'fails with unmatchable #to' do
expect {
set_the_flash.to(1).should
}.to raise_error('cannot match against 1')
expect { set_the_flash.to(1) }.to raise_error('cannot match against 1')
end
context 'a controller that sets a flash message' do
@ -21,13 +19,13 @@ describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do
end
it 'rejects setting a different flash message' do
controller_with_flash(:notice => 'hi').should_not
set_the_flash.to('other')
controller_with_flash(:notice => 'hi').
should_not set_the_flash.to('other')
end
it 'rejects setting a different pattern' do
controller_with_flash(:notice => 'hi').should_not
set_the_flash.to(/other/)
controller_with_flash(:notice => 'hi').
should_not set_the_flash.to(/other/)
end
end
@ -41,23 +39,23 @@ describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do
end
it 'accepts setting the exact flash.now message' do
controller_with_flash_now(:notice => 'hi').should
set_the_flash.now.to('hi')
controller_with_flash_now(:notice => 'hi').
should set_the_flash.now.to('hi')
end
it 'accepts setting a matched flash.now message' do
controller_with_flash_now(:notice => 'flasher').should
set_the_flash.now.to(/lash/)
controller_with_flash_now(:notice => 'flasher').
should set_the_flash.now.to(/lash/)
end
it 'rejects setting a different flash.now message' do
controller_with_flash_now(:notice => 'hi').should_not
set_the_flash.now.to('other')
controller_with_flash_now(:notice => 'hi').
should_not set_the_flash.now.to('other')
end
it 'rejects setting a different flash.now pattern' do
controller_with_flash_now(:notice => 'hi').should_not
set_the_flash.now.to(/other/)
controller_with_flash_now(:notice => 'hi').
should_not set_the_flash.now.to(/other/)
end
end
@ -70,28 +68,28 @@ describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do
end
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]
controller_with_flash(:notice => 'one', :alert => 'two').
should_not set_the_flash[:warning]
end
it 'accepts exact flash message of notice' do
controller_with_flash(:notice => 'one', :alert => 'two').should
set_the_flash[:notice].to('one')
controller_with_flash(:notice => 'one', :alert => 'two').
should set_the_flash[:notice].to('one')
end
it 'accepts setting a matched flash message of notice' do
controller_with_flash(:notice => 'one', :alert => 'two').should
set_the_flash[:notice].to(/on/)
controller_with_flash(:notice => 'one', :alert => 'two').
should set_the_flash[:notice].to(/on/)
end
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')
controller_with_flash(:notice => 'one', :alert => 'two').
should_not set_the_flash[:notice].to('other')
end
it 'rejects setting a different pattern' do
controller_with_flash(:notice => 'one', :alert => 'two').should_not
set_the_flash[:notice].to(/other/)
controller_with_flash(:notice => 'one', :alert => 'two').
should_not set_the_flash[:notice].to(/other/)
end
end

View File

@ -34,25 +34,25 @@ describe Shoulda::Matchers::ActiveModel::AllowValueMatcher do
end
it 'allows several good values' do
validating_format(:with => /abc/).should
allow_value('abcde', 'deabc').for(:attr)
validating_format(:with => /abc/).
should allow_value('abcde', 'deabc').for(:attr)
end
it 'rejects several bad values' do
validating_format(:with => /abc/).should_not
allow_value('xyz', 'zyx', nil, []).for(:attr)
validating_format(:with => /abc/).
should_not allow_value('xyz', 'zyx', nil, []).for(:attr)
end
end
context 'an attribute with a validation and a custom message' do
it 'allows a good value' do
validating_format(:with => /abc/, :message => 'bad value').should
allow_value('abcde').for(:attr).with_message(/bad/)
validating_format(:with => /abc/, :message => 'bad value').
should allow_value('abcde').for(:attr).with_message(/bad/)
end
it 'rejects a bad value' do
validating_format(:with => /abc/, :message => 'bad value').should_not
allow_value('xyz').for(:attr).with_message(/bad/)
validating_format(:with => /abc/, :message => 'bad value').
should_not allow_value('xyz').for(:attr).with_message(/bad/)
end
end
@ -94,21 +94,21 @@ describe Shoulda::Matchers::ActiveModel::AllowValueMatcher do
context 'with no values' do
it 'raises an error' do
expect { allow_value.for(:baz) }.to
raise_error(ArgumentError, /at least one argument/)
expect { allow_value.for(:baz) }.
to raise_error(ArgumentError, /at least one argument/)
end
end
if active_model_3_2?
context 'an attribute with a strict format validation' do
it 'strictly rejects a bad value' do
validating_format(:with => /abc/, :strict => true).should_not
allow_value('xyz').for(:attr).strict
validating_format(:with => /abc/, :strict => true).
should_not allow_value('xyz').for(:attr).strict
end
it 'strictly allows a bad value with a different message' do
validating_format(:with => /abc/, :strict => true).should
allow_value('xyz').for(:attr).with_message(/abc/).strict
validating_format(:with => /abc/, :strict => true).
should allow_value('xyz').for(:attr).with_message(/abc/).strict
end
it 'provides a useful negative failure message' do

View File

@ -17,8 +17,8 @@ describe Shoulda::Matchers::ActiveModel::DisallowValueMatcher do
context 'an attribute with a format validation and a custom message' do
it 'does not match if the value and message are both correct' do
validating_format(:with => /abc/, :message => 'good message').should_not
matcher('abcde').for(:attr).with_message('good message')
validating_format(:with => /abc/, :message => 'good message').
should_not matcher('abcde').for(:attr).with_message('good message')
end
it "delegates its failure message to its allow matcher's negative failure message" do
@ -32,8 +32,8 @@ describe Shoulda::Matchers::ActiveModel::DisallowValueMatcher do
end
it 'matches if the message is correct but the value is not' do
validating_format(:with => /abc/, :message => 'good message').should
matcher('xyz').for(:attr).with_message('good message')
validating_format(:with => /abc/, :message => 'good message').
should matcher('xyz').for(:attr).with_message('good message')
end
end

View File

@ -3,25 +3,25 @@ require 'spec_helper'
describe Shoulda::Matchers::ActiveModel::EnsureExclusionOfMatcher do
context 'an attribute which must be excluded from a range' do
it 'accepts ensuring the correct range' do
validating_exclusion(:in => 2..5).should
ensure_exclusion_of(:attr).in_range(2..5)
validating_exclusion(:in => 2..5).
should ensure_exclusion_of(:attr).in_range(2..5)
end
it 'rejects ensuring excluded value' do
validating_exclusion(:in => 2..5).should_not
ensure_exclusion_of(:attr).in_range(2..6)
validating_exclusion(:in => 2..5).
should_not ensure_exclusion_of(:attr).in_range(2..6)
end
it 'does not override the default message with a blank' do
validating_exclusion(:in => 2..5).should
ensure_exclusion_of(:attr).in_range(2..5).with_message(nil)
validating_exclusion(:in => 2..5).
should ensure_exclusion_of(:attr).in_range(2..5).with_message(nil)
end
end
context 'an attribute with a custom validation message' do
it 'accepts ensuring the correct range' do
validating_exclusion(:in => 2..4, :message => 'not good').should
ensure_exclusion_of(:attr).in_range(2..4).with_message(/not good/)
validating_exclusion(:in => 2..4, :message => 'not good').
should ensure_exclusion_of(:attr).in_range(2..4).with_message(/not good/)
end
end
@ -40,23 +40,29 @@ describe Shoulda::Matchers::ActiveModel::EnsureExclusionOfMatcher do
context 'an attribute which must be excluded from an array' do
it 'accepts with correct array' do
validating_exclusion(:in => %w(one two)).should
ensure_exclusion_of(:attr).in_array(%w(one two))
validating_exclusion(:in => %w(one two)).
should ensure_exclusion_of(:attr).in_array(%w(one two))
end
it 'rejects when only part of array matches' do
validating_exclusion(:in => %w(one two)).should_not
ensure_exclusion_of(:attr).in_array(%w(one wrong_value))
validating_exclusion(:in => %w(one two)).
should_not ensure_exclusion_of(:attr).in_array(%w(one wrong_value))
end
it 'rejects when array does not match at all' do
validating_exclusion(:in => %w(one two)).should_not
ensure_exclusion_of(:attr).in_array(%w(cat dog))
validating_exclusion(:in => %w(one two)).
should_not ensure_exclusion_of(:attr).in_array(%w(cat dog))
end
it 'has correct description' do
ensure_exclusion_of(:attr).in_array([true, 'dog']).description.should ==
'ensure exclusion of attr in [true, "dog"]'
ensure_exclusion_of(:attr).in_array([true, 'dog']).description.
should == 'ensure exclusion of attr in [true, "dog"]'
end
def validating_exclusion(options)
define_model(:example, :attr => :string) do
validates_exclusion_of :attr, options
end.new
end
end

View File

@ -3,15 +3,15 @@ require 'spec_helper'
describe Shoulda::Matchers::ActiveModel::EnsureInclusionOfMatcher do
context 'with no validations' do
it 'rejects an array which does not have a validator defined' do
define_model(:example, :attr => :string).new.should_not
ensure_inclusion_of(:attr).in_array(%w(Yes No))
define_model(:example, :attr => :string).new.
should_not ensure_inclusion_of(:attr).in_array(%w(Yes No))
end
end
context 'with true/false values' do
it 'can verify outside values to ensure the negative case' do
define_model(:example, :attr => :string).new.should_not
ensure_inclusion_of(:attr).in_array([true, false])
define_model(:example, :attr => :string).new.
should_not ensure_inclusion_of(:attr).in_array([true, false])
end
end
@ -26,40 +26,40 @@ describe Shoulda::Matchers::ActiveModel::EnsureInclusionOfMatcher do
context 'an attribute which must be included in a range' do
it 'accepts ensuring the correct range' do
validating_inclusion(:in => 2..5).should
ensure_inclusion_of(:attr).in_range(2..5)
validating_inclusion(:in => 2..5).
should ensure_inclusion_of(:attr).in_range(2..5)
end
it 'rejects ensuring a lower minimum value' do
validating_inclusion(:in => 2..5).should_not
ensure_inclusion_of(:attr).in_range(1..5)
validating_inclusion(:in => 2..5).
should_not ensure_inclusion_of(:attr).in_range(1..5)
end
it 'rejects ensuring a higher minimum value' do
validating_inclusion(:in => 2..5).should_not
ensure_inclusion_of(:attr).in_range(3..5)
validating_inclusion(:in => 2..5).
should_not ensure_inclusion_of(:attr).in_range(3..5)
end
it 'rejects ensuring a lower maximum value' do
validating_inclusion(:in => 2..5).should_not
ensure_inclusion_of(:attr).in_range(2..4)
validating_inclusion(:in => 2..5).
should_not ensure_inclusion_of(:attr).in_range(2..4)
end
it 'rejects ensuring a higher maximum value' do
validating_inclusion(:in => 2..5).should_not
ensure_inclusion_of(:attr).in_range(2..6)
validating_inclusion(:in => 2..5).
should_not ensure_inclusion_of(:attr).in_range(2..6)
end
it 'does not override the default message with a blank' do
validating_inclusion(:in => 2..5).should
ensure_inclusion_of(:attr).in_range(2..5).with_message(nil)
validating_inclusion(:in => 2..5).
should ensure_inclusion_of(:attr).in_range(2..5).with_message(nil)
end
end
context 'an attribute with a custom ranged value validation' do
it 'accepts ensuring the correct range' do
validating_inclusion(:in => 2..4, :message => 'not good').should
ensure_inclusion_of(:attr).in_range(2..4).with_message(/not good/)
validating_inclusion(:in => 2..4, :message => 'not good').
should ensure_inclusion_of(:attr).in_range(2..4).with_message(/not good/)
end
end
@ -80,85 +80,103 @@ describe Shoulda::Matchers::ActiveModel::EnsureInclusionOfMatcher do
context 'an attribute which must be included in an array' do
it 'accepts with correct array' do
validating_inclusion(:in => %w(one two)).should
ensure_inclusion_of(:attr).in_array(%w(one two))
validating_inclusion(:in => %w(one two)).
should ensure_inclusion_of(:attr).in_array(%w(one two))
end
it 'rejects when only part of array matches' do
validating_inclusion(:in => %w(one two)).should_not
ensure_inclusion_of(:attr).in_array(%w(one wrong_value))
validating_inclusion(:in => %w(one two)).
should_not ensure_inclusion_of(:attr).in_array(%w(one wrong_value))
end
it 'rejects when array does not match at all' do
validating_inclusion(:in => %w(one two)).should_not
ensure_inclusion_of(:attr).in_array(%w(cat dog))
validating_inclusion(:in => %w(one two)).
should_not ensure_inclusion_of(:attr).in_array(%w(cat dog))
end
it 'has correct description' do
ensure_inclusion_of(:attr).in_array([true, "dog"]).description.should ==
'ensure inclusion of attr in [true, "dog"]'
ensure_inclusion_of(:attr).in_array([true, "dog"]).description.
should == 'ensure inclusion of attr in [true, "dog"]'
end
it 'rejects allow_blank' do
validating_inclusion(:in => %w(one two)).should_not
ensure_inclusion_of(:attr).in_array(%w(one two)).allow_blank(true)
validating_inclusion(:in => %w(one two)).
should_not ensure_inclusion_of(:attr).in_array(%w(one two)).allow_blank(true)
end
it 'accepts allow_blank(false)' do
validating_inclusion(:in => %w(one two)).should
ensure_inclusion_of(:attr).in_array(%w(one two)).allow_blank(false)
validating_inclusion(:in => %w(one two)).
should ensure_inclusion_of(:attr).in_array(%w(one two)).allow_blank(false)
end
it 'rejects allow_nil' do
validating_inclusion(:in => %w(one two)).should_not
ensure_inclusion_of(:attr).in_array(%w(one two)).allow_nil(true)
validating_inclusion(:in => %w(one two)).
should_not ensure_inclusion_of(:attr).in_array(%w(one two)).allow_nil(true)
end
it 'accepts allow_nil(false)' do
validating_inclusion(:in => %w(one two)).should
ensure_inclusion_of(:attr).in_array(%w(one two)).allow_nil(false)
validating_inclusion(:in => %w(one two)).
should ensure_inclusion_of(:attr).in_array(%w(one two)).allow_nil(false)
end
def validating_inclusion(options)
define_model(:example, :attr => :string) do
validates_inclusion_of :attr, options
end.new
end
end
context 'with allowed blank and allowed nil' do
it 'accepts allow_blank' do
validating_inclusion(:in => %w(one two), :allow_blank => true).should
ensure_inclusion_of(:attr).in_array(%w(one two)).allow_blank
validating_inclusion(:in => %w(one two), :allow_blank => true).
should ensure_inclusion_of(:attr).in_array(%w(one two)).allow_blank
end
it 'rejects allow_blank(false)' do
validating_inclusion(:in => %w(one two), :allow_blank => true).should_not
ensure_inclusion_of(:attr).in_array(%w(one two)).allow_blank(false)
validating_inclusion(:in => %w(one two), :allow_blank => true).
should_not ensure_inclusion_of(:attr).in_array(%w(one two)).allow_blank(false)
end
it 'accepts allow_nil' do
validating_inclusion(:in => %w(one two), :allow_nil => true).should
ensure_inclusion_of(:attr).in_array(%w(one two)).allow_nil
validating_inclusion(:in => %w(one two), :allow_nil => true).
should ensure_inclusion_of(:attr).in_array(%w(one two)).allow_nil
end
it 'rejects allow_nil' do
validating_inclusion(:in => %w(one two), :allow_nil => true).should_not
ensure_inclusion_of(:attr).in_array(%w(one two)).allow_nil(false)
validating_inclusion(:in => %w(one two), :allow_nil => true).
should_not ensure_inclusion_of(:attr).in_array(%w(one two)).allow_nil(false)
end
def validating_inclusion(options)
define_model(:example, :attr => :string) do
validates_inclusion_of :attr, options
end.new
end
end
context 'an attribute allowing some blank values but not others' do
it 'rejects allow_blank' do
validating_inclusion(:in => ['one', 'two', '']).should_not
ensure_inclusion_of(:attr).in_array(['one', 'two', '']).allow_blank(true)
validating_inclusion(:in => ['one', 'two', '']).
should_not ensure_inclusion_of(:attr).in_array(['one', 'two', '']).allow_blank(true)
end
def validating_inclusion(options)
define_model(:example, :attr => :string) do
validates_inclusion_of :attr, options
end.new
end
end
if active_model_3_2?
context 'a strict attribute which must be included in a range' do
it 'accepts ensuring the correct range' do
validating_inclusion(:in => 2..5, :strict => true).should
ensure_inclusion_of(:attr).in_range(2..5).strict
validating_inclusion(:in => 2..5, :strict => true).
should ensure_inclusion_of(:attr).in_range(2..5).strict
end
it 'rejects ensuring another range' do
validating_inclusion(:in => 2..5, :strict => true).should_not
ensure_inclusion_of(:attr).in_range(2..6).strict
validating_inclusion(:in => 2..5, :strict => true).
should_not ensure_inclusion_of(:attr).in_range(2..6).strict
end
end
end

View File

@ -3,51 +3,52 @@ require 'spec_helper'
describe Shoulda::Matchers::ActiveModel::EnsureLengthOfMatcher do
context 'an attribute with a non-zero minimum length validation' do
it 'accepts ensuring the correct minimum length' do
validating_length(:minimum => 4).should
ensure_length_of(:attr).is_at_least(4)
validating_length(:minimum => 4).
should ensure_length_of(:attr).is_at_least(4)
end
it 'rejects ensuring a lower minimum length with any message' do
validating_length(:minimum => 4).should_not
ensure_length_of(:attr).is_at_least(3).with_short_message(/.*/)
validating_length(:minimum => 4).
should_not ensure_length_of(:attr).is_at_least(3).with_short_message(/.*/)
end
it 'rejects ensuring a higher minimum length with any message' do
validating_length(:minimum => 4).should_not
ensure_length_of(:attr).is_at_least(5).with_short_message(/.*/)
validating_length(:minimum => 4).
should_not ensure_length_of(:attr).is_at_least(5).with_short_message(/.*/)
end
it 'does not override the default message with a blank' do
validating_length(:minimum => 4).should
ensure_length_of(:attr).is_at_least(4).with_short_message(nil)
validating_length(:minimum => 4).
should ensure_length_of(:attr).is_at_least(4).with_short_message(nil)
end
end
context 'an attribute with a minimum length validation of 0' do
it 'accepts ensuring the correct minimum length' do
validating_length(:minimum => 0).should
ensure_length_of(:attr).is_at_least(0) end
validating_length(:minimum => 0).
should ensure_length_of(:attr).is_at_least(0)
end
end
context 'an attribute with a maximum length' do
it 'accepts ensuring the correct maximum length' do
validating_length(:maximum => 4).should
ensure_length_of(:attr).is_at_most(4)
validating_length(:maximum => 4).
should ensure_length_of(:attr).is_at_most(4)
end
it 'rejects ensuring a lower maximum length with any message' do
validating_length(:maximum => 4).should_not
ensure_length_of(:attr).is_at_most(3).with_long_message(/.*/)
validating_length(:maximum => 4).
should_not ensure_length_of(:attr).is_at_most(3).with_long_message(/.*/)
end
it 'rejects ensuring a higher maximum length with any message' do
validating_length(:maximum => 4).should_not
ensure_length_of(:attr).is_at_most(5).with_long_message(/.*/)
validating_length(:maximum => 4).
should_not ensure_length_of(:attr).is_at_most(5).with_long_message(/.*/)
end
it 'does not override the default message with a blank' do
validating_length(:maximum => 4).should
ensure_length_of(:attr).is_at_most(4).with_long_message(nil)
validating_length(:maximum => 4).
should ensure_length_of(:attr).is_at_most(4).with_long_message(nil)
end
end
@ -57,18 +58,18 @@ describe Shoulda::Matchers::ActiveModel::EnsureLengthOfMatcher do
end
it 'rejects ensuring a lower maximum length with any message' do
validating_length(:is => 4).should_not
ensure_length_of(:attr).is_equal_to(3).with_message(/.*/)
validating_length(:is => 4).
should_not ensure_length_of(:attr).is_equal_to(3).with_message(/.*/)
end
it 'rejects ensuring a higher maximum length with any message' do
validating_length(:is => 4).should_not
ensure_length_of(:attr).is_equal_to(5).with_message(/.*/)
validating_length(:is => 4).
should_not ensure_length_of(:attr).is_equal_to(5).with_message(/.*/)
end
it 'does not override the default message with a blank' do
validating_length(:is => 4).should
ensure_length_of(:attr).is_equal_to(4).with_message(nil)
validating_length(:is => 4).
should ensure_length_of(:attr).is_equal_to(4).with_message(nil)
end
end
@ -85,22 +86,22 @@ describe Shoulda::Matchers::ActiveModel::EnsureLengthOfMatcher do
context 'an attribute with a custom minimum length validation' do
it 'accepts ensuring the correct minimum length' do
validating_length(:minimum => 4, :too_short => 'foobar').should
ensure_length_of(:attr).is_at_least(4).with_short_message(/foo/)
validating_length(:minimum => 4, :too_short => 'foobar').
should ensure_length_of(:attr).is_at_least(4).with_short_message(/foo/)
end
end
context 'an attribute with a custom maximum length validation' do
it 'accepts ensuring the correct minimum length' do
validating_length(:maximum => 4, :too_long => 'foobar').should
ensure_length_of(:attr).is_at_most(4).with_long_message(/foo/)
validating_length(:maximum => 4, :too_long => 'foobar').
should ensure_length_of(:attr).is_at_most(4).with_long_message(/foo/)
end
end
context 'an attribute without a length validation' do
it 'rejects ensuring a minimum length' do
define_model(:example, :attr => :string).new.should_not
ensure_length_of(:attr).is_at_least(1)
define_model(:example, :attr => :string).new.
should_not ensure_length_of(:attr).is_at_least(1)
end
end

View File

@ -18,13 +18,11 @@ describe Shoulda::Matchers::ActiveModel::OnlyIntegerMatcher do
context 'given an attribute that only allows integer values with a custom validation message' do
it 'only accepts integer values for that attribute with that message' do
only_integer(:message => 'custom').should
new_matcher.with_message(/custom/)
only_integer(:message => 'custom').should new_matcher.with_message(/custom/)
end
it 'rejects integer values for that attribute with another message' do
only_integer(:message => 'custom').should_not
new_matcher.with_message(/wrong/)
only_integer(:message => 'custom').should_not new_matcher.with_message(/wrong/)
end
end

View File

@ -19,13 +19,13 @@ describe Shoulda::Matchers::ActiveModel::ValidateAcceptanceOfMatcher do
context 'an attribute which must be accepted with a custom message' do
it 'accepts when the message matches' do
validating_acceptance(:message => 'custom').should
matcher.with_message(/custom/)
validating_acceptance(:message => 'custom').
should matcher.with_message(/custom/)
end
it 'rejects when the message does not match' do
validating_acceptance(:message => 'custom').should_not
matcher.with_message(/wrong/)
validating_acceptance(:message => 'custom').
should_not matcher.with_message(/wrong/)
end
end

View File

@ -19,13 +19,13 @@ describe Shoulda::Matchers::ActiveModel::ValidateConfirmationOfMatcher do
context 'a confirmation validation with a custom message' do
it 'accepts when the message matches' do
validating_confirmation(:message => 'custom').should
matcher.with_message(/custom/)
validating_confirmation(:message => 'custom').
should matcher.with_message(/custom/)
end
it 'rejects when the messages do not match' do
validating_confirmation(:message => 'custom').should_not
matcher.with_message(/wrong/)
validating_confirmation(:message => 'custom').
should_not matcher.with_message(/wrong/)
end
end

View File

@ -42,37 +42,37 @@ describe Shoulda::Matchers::ActiveModel::ValidateFormatOfMatcher do
context 'when allow_blank or allow_nil are set' do
it 'is valid when attr is nil' do
validating_format(:with => /abc/, :allow_nil => true).should
matcher.with(nil)
validating_format(:with => /abc/, :allow_nil => true).
should matcher.with(nil)
end
it 'is valid when attr is blank' do
validating_format(:with => /abc/, :allow_blank => true).should
matcher.with(' ')
validating_format(:with => /abc/, :allow_blank => true).
should matcher.with(' ')
end
end
context '#allow_blank' do
it 'accepts when allow_blank matches' do
validating_format(:with => /abc/, :allow_blank => true).should
matcher.allow_blank
validating_format(:with => /abc/, :allow_blank => true).
should matcher.allow_blank
end
it 'rejects when allow_blank does not match' do
validating_format(:with => /abc/, :allow_blank => false).should_not
matcher.allow_blank
validating_format(:with => /abc/, :allow_blank => false).
should_not matcher.allow_blank
end
end
context '#allow_nil' do
it 'accepts when allow_nil matches' do
validating_format(:with => /abc/, :allow_nil => true).should
matcher.allow_nil
validating_format(:with => /abc/, :allow_nil => true).
should matcher.allow_nil
end
it 'rejects when allow_nil does not match' do
validating_format(:with => /abc/, :allow_nil => false).should_not
matcher.allow_nil
validating_format(:with => /abc/, :allow_nil => false).
should_not matcher.allow_nil
end
end

View File

@ -51,13 +51,13 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher do
context 'with a custom validation message' do
it 'accepts when the messages match' do
validating_numericality(:message => 'custom').should
matcher.with_message(/custom/)
validating_numericality(:message => 'custom').
should matcher.with_message(/custom/)
end
it 'rejects when the messages do not match' do
validating_numericality(:message => 'custom').should_not
matcher.with_message(/wrong/)
validating_numericality(:message => 'custom').
should_not matcher.with_message(/wrong/)
end
end

View File

@ -29,8 +29,8 @@ describe Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher do
context 'an ActiveModel class without a presence validation' do
it 'rejects' do
define_active_model_class('Example', :accessors => [:attr]).new.should_not
matcher
define_active_model_class('Example', :accessors => [:attr]).new.
should_not matcher
end
end
@ -42,8 +42,8 @@ describe Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher do
context 'a has_many association without a presence validation' do
it 'does not require the attribute to be set' do
has_many_children(:presence => false).should_not
validate_presence_of(:children)
has_many_children(:presence => false).
should_not validate_presence_of(:children)
end
end
@ -94,8 +94,8 @@ describe Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher do
end
it 'does not override the default message with a blank' do
validating_presence(:strict => true).should
matcher.strict.with_message(nil)
validating_presence(:strict => true).
should matcher.strict.with_message(nil)
end
end

View File

@ -79,8 +79,8 @@ describe Shoulda::Matchers::ActiveModel::ValidateUniquenessOfMatcher do
context 'a model with a scoped uniqueness validation with an existing value' do
it 'accepts when the correct scope is specified' do
validating_scoped_uniqueness([:scope1, :scope2]).should
matcher.scoped_to(:scope1, :scope2)
validating_scoped_uniqueness([:scope1, :scope2]).
should matcher.scoped_to(:scope1, :scope2)
end
it 'accepts when the subject is an existing record' do
@ -89,18 +89,18 @@ describe Shoulda::Matchers::ActiveModel::ValidateUniquenessOfMatcher do
end
it 'rejects when too narrow of a scope is specified' do
validating_scoped_uniqueness([:scope1, :scope2]).should_not
matcher.scoped_to(:scope1, :scope2, :other)
validating_scoped_uniqueness([:scope1, :scope2]).
should_not matcher.scoped_to(:scope1, :scope2, :other)
end
it 'rejects when too broad of a scope is specified' do
validating_scoped_uniqueness([:scope1, :scope2]).should_not
matcher.scoped_to(:scope1)
validating_scoped_uniqueness([:scope1, :scope2]).
should_not matcher.scoped_to(:scope1)
end
it 'rejects when a different scope is specified' do
validating_scoped_uniqueness([:scope1]).should_not
matcher.scoped_to(:other)
validating_scoped_uniqueness([:scope1]).
should_not matcher.scoped_to(:other)
end
it 'rejects when no scope is specified' do
@ -108,8 +108,8 @@ describe Shoulda::Matchers::ActiveModel::ValidateUniquenessOfMatcher do
end
it 'rejects when a non-existent attribute is specified as a scope' do
validating_scoped_uniqueness([:scope1]).should_not
matcher.scoped_to(:fake)
validating_scoped_uniqueness([:scope1]).
should_not matcher.scoped_to(:fake)
end
def create_existing_record
@ -133,20 +133,20 @@ describe Shoulda::Matchers::ActiveModel::ValidateUniquenessOfMatcher do
context 'a model with a case-sensitive uniqueness validation on a string attribute and an existing record' do
it 'accepts a case-sensitive value for that attribute' do
case_sensitive_validation_with_existing_value(:string).should
matcher
case_sensitive_validation_with_existing_value(:string).
should matcher
end
it 'rejects a case-insensitive value for that attribute' do
case_sensitive_validation_with_existing_value(:string).should_not
matcher.case_insensitive
case_sensitive_validation_with_existing_value(:string).
should_not matcher.case_insensitive
end
end
context 'a model with a case-sensitive uniqueness validation on an integer attribute with an existing value' do
it 'accepts a case-insensitive value for that attribute' do
case_sensitive_validation_with_existing_value(:integer).should
matcher.case_insensitive
case_sensitive_validation_with_existing_value(:integer).
should matcher.case_insensitive
end
it 'accepts a case-sensitive value for that attribute' do

View File

@ -59,13 +59,13 @@ describe Shoulda::Matchers::ActiveRecord::AcceptNestedAttributesForMatcher do
context 'update_only' do
it 'accepts a valid truthy value' do
accepting_children(:update_only => true).should
children_matcher.update_only(true)
accepting_children(:update_only => true).
should children_matcher.update_only(true)
end
it 'accepts a valid falsey value' do
accepting_children(:update_only => false).should
children_matcher.update_only(false)
accepting_children(:update_only => false).
should children_matcher.update_only(false)
end
it 'rejects an invalid truthy value' do

View File

@ -38,8 +38,8 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
end
it 'accepts an association with a valid :dependent option' do
belonging_to_parent(:dependent => :destroy).should
belong_to(:parent).dependent(:destroy)
belonging_to_parent(:dependent => :destroy).
should belong_to(:parent).dependent(:destroy)
end
it 'rejects an association with a bad :dependent option' do
@ -65,35 +65,35 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
end
it 'accepts an association with a valid :class_name option' do
belonging_to_parent(:class_name => 'TreeParent').should
belong_to(:parent).class_name('TreeParent')
belonging_to_parent(:class_name => 'TreeParent').
should belong_to(:parent).class_name('TreeParent')
end
it 'rejects an association with a bad :class_name option' do
belonging_to_parent(:class_name => 'TreeParent').should_not
belong_to(:parent).class_name('TreeChild')
belonging_to_parent(:class_name => 'TreeParent').
should_not belong_to(:parent).class_name('TreeChild')
end
context 'validate' do
[false, true].each do |validate_value|
context 'when the model has :validate => #{validate_value}' do
it 'accepts a matching validate option' do
belonging_to_parent(:validate => validate_value).should
belong_to(:parent).validate(validate_value)
belonging_to_parent(:validate => validate_value).
should belong_to(:parent).validate(validate_value)
end
it 'rejects a non-matching validate option' do
belonging_to_parent(:validate => validate_value).should_not
belong_to(:parent).validate(!validate_value)
belonging_to_parent(:validate => validate_value).
should_not belong_to(:parent).validate(!validate_value)
end
it 'defaults to validate(true)' do
if validate_value
belonging_to_parent(:validate => validate_value).should
belong_to(:parent).validate
belonging_to_parent(:validate => validate_value).
should belong_to(:parent).validate
else
belonging_to_parent(:validate => validate_value).should_not
belong_to(:parent).validate
belonging_to_parent(:validate => validate_value).
should_not belong_to(:parent).validate
end
end
end
@ -132,7 +132,7 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
define_model :conception, :child_id => :integer,
:parent_id => :integer do
belongs_to :child
end
end
define_model :parent do
has_many :conceptions
has_many :children, :through => :conceptions
@ -181,7 +181,7 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
define_model :conception, :child_id => :integer,
:parent_id => :integer do
belongs_to :child
end
end
define_model :parent do
has_many :conceptions
has_many :relationships
@ -194,8 +194,8 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
end
it 'accepts an association with a valid :dependent option' do
having_many_children(:dependent => :destroy).should
have_many(:children).dependent(:destroy)
having_many_children(:dependent => :destroy).
should have_many(:children).dependent(:destroy)
end
it 'rejects an association with a bad :dependent option' do
@ -203,8 +203,8 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
end
it 'accepts an association with a valid :order option' do
having_many_children(:order => :id).should
have_many(:children).order(:id)
having_many_children(:order => :id).
should have_many(:children).order(:id)
end
it 'rejects an association with a bad :order option' do
@ -252,8 +252,7 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
end
it 'assumes validate() means validate(true)' do
having_many_children(:validate => false).should_not
have_many(:children).validate
having_many_children(:validate => false).should_not have_many(:children).validate
end
it 'matches validate(false) to having no validate option specified' do
@ -334,8 +333,8 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
end
it 'accepts an association with a valid :dependent option' do
having_one_detail(:dependent => :destroy).should
have_one(:detail).dependent(:destroy)
having_one_detail(:dependent => :destroy).
should have_one(:detail).dependent(:destroy)
end
it 'rejects an association with a bad :dependent option' do
@ -369,8 +368,12 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
end
it 'accepts an association with a valid :class_name option' do
having_one_detail(:class_name => 'PersonDetail').should
have_one(:detail).class_name('PersonDetail')
define_model :person_detail, :person_id => :integer
define_model :person do
has_one :detail, :class_name => 'PersonDetail'
end
Person.new.should have_one(:detail).class_name('PersonDetail')
end
it 'rejects an association with a bad :class_name option' do
@ -398,17 +401,18 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
context 'validate' do
it 'accepts when the :validate option matches' do
having_one_detail(:validate => false).should
have_one(:detail).validate(false)
having_one_detail(:validate => false).
should have_one(:detail).validate(false)
end
it 'rejects when the :validate option does not match' do
having_one_detail(:validate => true).should_not
have_one(:detail).validate(false) end
having_one_detail(:validate => true).
should_not have_one(:detail).validate(false)
end
it 'assumes validate() means validate(true)' do
having_one_detail(:validate => false).should_not
have_one(:detail).validate
having_one_detail(:validate => false).
should_not have_one(:detail).validate
end
it 'matches validate(false) to having no validate option specified' do
@ -426,9 +430,9 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
context 'have_and_belong_to_many' do
it 'accepts a valid association' do
having_and_belonging_to_many_relatives.should
have_and_belong_to_many(:relatives)
end
having_and_belonging_to_many_relatives.
should have_and_belong_to_many(:relatives)
end
it 'rejects a nonexistent association' do
define_model :relatives
@ -465,8 +469,7 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
define_model :people_relative, :id => false, :person_id => :integer,
:relative_id => :integer
Person.new.should
have_and_belong_to_many(:relatives).conditions(:adopted => true)
Person.new.should have_and_belong_to_many(:relatives).conditions(:adopted => true)
end
it 'rejects an association with a bad :conditions option' do
@ -477,8 +480,7 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
define_model :people_relative, :id => false, :person_id => :integer,
:relative_id => :integer
Person.new.should_not
have_and_belong_to_many(:relatives).conditions(:adopted => true)
Person.new.should_not have_and_belong_to_many(:relatives).conditions(:adopted => true)
end
it 'accepts an association with a valid :class_name option' do
@ -490,34 +492,33 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
define_model :people_person_relative, :person_id => :integer,
:person_relative_id => :integer
Person.new.should
have_and_belong_to_many(:relatives).class_name('PersonRelatives')
Person.new.should have_and_belong_to_many(:relatives).class_name('PersonRelatives')
end
it 'rejects an association with a bad :class_name option' do
having_and_belonging_to_many_relatives.should_not
have_and_belong_to_many(:relatives).class_name('PersonRelatives')
having_and_belonging_to_many_relatives.
should_not have_and_belong_to_many(:relatives).class_name('PersonRelatives')
end
context 'validate' do
it 'accepts when the :validate option matches' do
having_and_belonging_to_many_relatives(:validate => false).should
have_and_belong_to_many(:relatives).validate(false)
having_and_belonging_to_many_relatives(:validate => false).
should have_and_belong_to_many(:relatives).validate(false)
end
it 'rejects when the :validate option does not match' do
having_and_belonging_to_many_relatives(:validate => true).should
have_and_belong_to_many(:relatives).validate(false)
having_and_belonging_to_many_relatives(:validate => true).
should have_and_belong_to_many(:relatives).validate(false)
end
it 'assumes validate() means validate(true)' do
having_and_belonging_to_many_relatives(:validate => false).should_not
have_and_belong_to_many(:relatives).validate
having_and_belonging_to_many_relatives(:validate => false).
should_not have_and_belong_to_many(:relatives).validate
end
it 'matches validate(false) to having no validate option specified' do
having_and_belonging_to_many_relatives.should
have_and_belong_to_many(:relatives).validate(false)
having_and_belonging_to_many_relatives.
should have_and_belong_to_many(:relatives).validate(false)
end
end

View File

@ -11,90 +11,90 @@ describe Shoulda::Matchers::ActiveRecord::HaveDbColumnMatcher do
context '#of_type' do
it 'accepts a column of correct type' do
model(:nickname => :string).should
have_db_column(:nickname).of_type(:string)
model(:nickname => :string).
should have_db_column(:nickname).of_type(:string)
end
it 'rejects a nonexistent database column' do
define_model(:superhero).should_not
have_db_column(:nickname).of_type(:string)
define_model(:superhero).new.
should_not have_db_column(:nickname).of_type(:string)
end
it 'rejects a column of wrong type' do
model(:nickname => :integer).should_not
have_db_column(:nickname).of_type(:string)
model(:nickname => :integer).
should_not have_db_column(:nickname).of_type(:string)
end
end
context 'with precision option' do
it 'accepts a column of correct precision' do
with_table(:salary, :decimal, :precision => 5).should
have_db_column(:salary).with_options(:precision => 5)
with_table(:salary, :decimal, :precision => 5).
should have_db_column(:salary).with_options(:precision => 5)
end
it 'rejects a column of wrong precision' do
with_table(:salary, :decimal, :precision => 6).should_not
have_db_column(:salary).with_options(:precision => 5)
with_table(:salary, :decimal, :precision => 6).
should_not have_db_column(:salary).with_options(:precision => 5)
end
end
context 'with limit option' do
it 'accepts a column of correct limit' do
with_table(:email, :string, :limit => 255).should
have_db_column(:email).with_options(:limit => 255)
with_table(:email, :string, :limit => 255).
should have_db_column(:email).with_options(:limit => 255)
end
it 'rejects a column of wrong limit' do
with_table(:email, :string, :limit => 100).should_not
have_db_column(:email).with_options(:limit => 255)
with_table(:email, :string, :limit => 100).
should_not have_db_column(:email).with_options(:limit => 255)
end
end
context 'with default option' do
it 'accepts a column with correct default' do
with_table(:admin, :boolean, :default => false).should
have_db_column(:admin).with_options(:default => false)
with_table(:admin, :boolean, :default => false).
should have_db_column(:admin).with_options(:default => false)
end
it 'rejects a column with wrong default' do
with_table(:admin, :boolean, :default => true).should_not
have_db_column(:admin).with_options(:default => false)
with_table(:admin, :boolean, :default => true).
should_not have_db_column(:admin).with_options(:default => false)
end
end
context 'with null option' do
it 'accepts a column of correct null' do
with_table(:admin, :boolean, :null => false).should
have_db_column(:admin).with_options(:null => false)
with_table(:admin, :boolean, :null => false).
should have_db_column(:admin).with_options(:null => false)
end
it 'rejects a column of wrong null' do
with_table(:admin, :boolean, :null => true).should_not
have_db_column(:admin).with_options(:null => false)
with_table(:admin, :boolean, :null => true).
should_not have_db_column(:admin).with_options(:null => false)
end
end
context 'with scale option' do
it 'accepts a column of correct scale' do
with_table(:salary, :decimal, :scale => 2).should
have_db_column(:salary).with_options(:scale => 2)
with_table(:salary, :decimal, :precision => 10, :scale => 2).
should have_db_column(:salary).with_options(:scale => 2)
end
it 'rejects a column of wrong scale' do
with_table(:salary, :decimal, :scale => 4).should_not
have_db_column(:salary).with_options(:scale => 2)
with_table(:salary, :decimal, :precision => 10, :scale => 4).
should_not have_db_column(:salary).with_options(:scale => 2)
end
end
context 'with primary option' do
it 'accepts a column that is primary' do
with_table(:id, :integer, :primary => true).should
have_db_column(:id).with_options(:primary => true)
with_table(:id, :integer, :primary => true).
should have_db_column(:id).with_options(:primary => true)
end
it 'rejects a column that is not primary' do
with_table(:whatever, :integer, :primary => false).should_not
have_db_column(:whatever).with_options(:primary => true)
with_table(:whatever, :integer, :primary => false).
should_not have_db_column(:whatever).with_options(:primary => true)
end
end

View File

@ -13,13 +13,13 @@ describe Shoulda::Matchers::ActiveRecord::HaveDbIndexMatcher do
context 'have_db_index with unique option' do
it 'accepts an index of correct unique' do
with_index_on(:ssn, :unique => true).should
have_db_index(:ssn).unique(true)
with_index_on(:ssn, :unique => true).
should have_db_index(:ssn).unique(true)
end
it 'rejects an index of wrong unique' do
with_index_on(:ssn, :unique => false).should_not
have_db_index(:ssn).unique(true)
with_index_on(:ssn, :unique => false).
should_not have_db_index(:ssn).unique(true)
end
end
@ -30,8 +30,8 @@ describe Shoulda::Matchers::ActiveRecord::HaveDbIndexMatcher do
table.string :geocodable_type
end
db_connection.add_index :geocodings, [:geocodable_type, :geocodable_id]
define_model_class('Geocoding').new.should
have_db_index([:geocodable_type, :geocodable_id])
define_model_class('Geocoding').new.
should have_db_index([:geocodable_type, :geocodable_id])
end
it 'rejects a nonexistent index' do
@ -39,8 +39,8 @@ describe Shoulda::Matchers::ActiveRecord::HaveDbIndexMatcher do
table.integer :geocodable_id
table.string :geocodable_type
end
define_model_class('Geocoding').new.should_not
have_db_index([:geocodable_type, :geocodable_id])
define_model_class('Geocoding').new.
should_not have_db_index([:geocodable_type, :geocodable_id])
end
end

View File

@ -19,8 +19,8 @@ describe Shoulda::Matchers::ActiveRecord::HaveReadonlyAttributeMatcher do
context 'an attribute on a class with no readonly attributes' do
it 'rejects being read-only' do
define_model(:example, :attr => :string).new.should_not
have_readonly_attribute(:attr)
define_model(:example, :attr => :string).new.
should_not have_readonly_attribute(:attr)
end
it 'assigns a failure message' do

View File

@ -49,22 +49,21 @@ describe Shoulda::Matchers::ActiveRecord::SerializeMatcher do
end
it 'rejects when using as_instance_of' do
with_serialized_attr(Hash).should_not
serialize(:attr).as_instance_of(Hash)
with_serialized_attr(Hash).should_not serialize(:attr).as_instance_of(Hash)
end
end
context 'a serializer that is an instance of a class' do
it 'accepts when using #as_instance_of' do
define_serializer(:ExampleSerializer)
with_serialized_attr(ExampleSerializer.new).should
serialize(:attr).as_instance_of(ExampleSerializer)
with_serialized_attr(ExampleSerializer.new).
should serialize(:attr).as_instance_of(ExampleSerializer)
end
it 'rejects when using #as' do
define_serializer(:ExampleSerializer)
with_serialized_attr(ExampleSerializer.new).should_not
serialize(:attr).as(ExampleSerializer)
with_serialized_attr(ExampleSerializer.new).
should_not serialize(:attr).as(ExampleSerializer)
end
end

View File

@ -47,13 +47,13 @@ describe Shoulda::Matchers::Independent::DelegateMatcher do
end
it 'raises an error if no delegation target is defined' do
expect { Object.new.should delegate_method(:name) }.to raise_exception
described_class::TargetNotDefinedError
expect { Object.new.should delegate_method(:name) }.
to raise_exception described_class::TargetNotDefinedError
end
it 'raises an error if called with #should_not' do
expect { Object.new.should_not delegate_method(:name).to(:anyone) }.to
raise_exception described_class::InvalidDelegateMatcher
expect { Object.new.should_not delegate_method(:name).to(:anyone) }.
to raise_exception described_class::InvalidDelegateMatcher
end
context 'given a method that does not delegate' do
@ -164,8 +164,8 @@ describe Shoulda::Matchers::Independent::DelegateMatcher do
context 'when given the correct method name' do
it 'accepts' do
PostOffice.new.should
delegate_method(:deliver_mail).to(:mailman).as(:deliver_mail_and_avoid_dogs)
PostOffice.new.
should delegate_method(:deliver_mail).to(:mailman).as(:deliver_mail_and_avoid_dogs)
end
end