Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Convert to RSpec expect syntax

  • Loading branch information...
commit 4e74ba8e48a421d5b7ba6f51a155c7dbea45393c 1 parent dfce983
@mcmire mcmire authored
Showing with 702 additions and 696 deletions.
  1. +1 −1  lib/shoulda/matchers/action_controller.rb
  2. +3 −3 spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb
  3. +9 −9 spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb
  4. +16 −16 spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb
  5. +6 −6 spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb
  6. +9 −9 spec/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb
  7. +4 −4 spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb
  8. +10 −10 spec/shoulda/matchers/action_controller/route_matcher_spec.rb
  9. +6 −6 spec/shoulda/matchers/action_controller/route_params_spec.rb
  10. +10 −10 spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
  11. +36 −36 spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb
  12. +15 −15 spec/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb
  13. +28 −28 spec/shoulda/matchers/active_model/allow_value_matcher_spec.rb
  14. +13 −13 spec/shoulda/matchers/active_model/disallow_value_matcher_spec.rb
  15. +22 −22 spec/shoulda/matchers/active_model/ensure_exclusion_of_matcher_spec.rb
  16. +57 −57 spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb
  17. +37 −37 spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb
  18. +8 −8 spec/shoulda/matchers/active_model/exception_message_finder_spec.rb
  19. +6 −4 spec/shoulda/matchers/active_model/helpers_spec.rb
  20. +11 −11 spec/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb
  21. +12 −12 spec/shoulda/matchers/active_model/numericality_matchers/odd_even_number_matcher_spec.rb
  22. +7 −7 spec/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb
  23. +15 −15 spec/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb
  24. +7 −7 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
  25. +8 −8 spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb
  26. +22 −22 spec/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb
  27. +20 −20 spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb
  28. +62 −62 spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb
  29. +10 −10 spec/shoulda/matchers/active_model/validation_message_finder_spec.rb
  30. +21 −21 spec/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb
  31. +138 −138 spec/shoulda/matchers/active_record/association_matcher_spec.rb
  32. +32 −32 spec/shoulda/matchers/active_record/have_db_column_matcher_spec.rb
  33. +15 −15 spec/shoulda/matchers/active_record/have_db_index_matcher_spec.rb
  34. +5 −5 spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
  35. +12 −12 spec/shoulda/matchers/active_record/serialize_matcher_spec.rb
  36. +4 −0 spec/spec_helper.rb
  37. +5 −5 spec/support/shared_examples/numerical_submatcher_spec.rb
View
2  lib/shoulda/matchers/action_controller.rb
@@ -26,7 +26,7 @@ module Matchers
# it { should not_set_the_flash) }
#
# it 'does something else really cool' do
- # assigns[:user].id.should == 1
+ # expect(assigns[:user].id).to eq 1
# end
# end
#
View
6 spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb
@@ -4,16 +4,16 @@
it 'accepts filtering a filtered parameter' do
filter(:secret)
- nil.should filter_param(:secret)
+ expect(nil).to filter_param(:secret)
end
it 'rejects filtering an unfiltered parameter' do
filter(:secret)
matcher = filter_param(:other)
- matcher.matches?(nil).should be_false
+ expect(matcher.matches?(nil)).to eq false
- matcher.failure_message.should =~ /Expected other to be filtered.*secret/
+ expect(matcher.failure_message).to match(/Expected other to be filtered.*secret/)
end
def filter(param)
View
18 spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb
@@ -3,22 +3,22 @@
describe Shoulda::Matchers::ActionController::RedirectToMatcher do
context 'a controller that redirects' do
it 'accepts redirecting to that url' do
- controller_redirecting_to('/some/url').should redirect_to('/some/url')
+ expect(controller_redirecting_to('/some/url')).to redirect_to('/some/url')
end
it 'rejects redirecting to a different url' do
- controller_redirecting_to('/some/url').
- should_not redirect_to('/some/other/url')
+ expect(controller_redirecting_to('/some/url')).
+ not_to 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' }
+ expect(controller_redirecting_to('/some/url')).
+ to 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' }
+ expect(controller_redirecting_to('/some/url')).
+ not_to redirect_to('somewhere else') { '/some/other/url' }
end
def controller_redirecting_to(url)
@@ -30,13 +30,13 @@ def controller_redirecting_to(url)
it 'rejects redirecting to a url' do
controller = build_response { render text: 'hello' }
- controller.should_not redirect_to('/some/url')
+ expect(controller).not_to redirect_to('/some/url')
end
end
it 'provides the correct description when provided a block' do
matcher = redirect_to('somewhere else') { '/some/other/url' }
- matcher.description.should eq 'redirect to somewhere else'
+ expect(matcher.description).to eq 'redirect to somewhere else'
end
end
View
32 spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb
@@ -5,19 +5,19 @@
context 'a controller that renders a template' do
it 'accepts rendering that template' do
- controller_with_show.should render_template(:show)
+ expect(controller_with_show).to render_template(:show)
end
it 'rejects rendering a different template' do
- controller_with_show.should_not render_template(:index)
+ expect(controller_with_show).not_to render_template(:index)
end
it 'accepts rendering that template in the given context' do
- controller_with_show.should render_template(:show).in_context(self)
+ expect(controller_with_show).to render_template(:show).in_context(self)
end
it 'rejects rendering a different template in the given context' do
- controller_with_show.should_not render_template(:index).in_context(self)
+ expect(controller_with_show).not_to render_template(:index).in_context(self)
end
def controller_with_show
@@ -27,23 +27,23 @@ def controller_with_show
context 'a controller that renders a partial' do
it 'accepts rendering that partial' do
- controller_with_customer_partial.
- should render_template(partial: '_customer')
+ expect(controller_with_customer_partial).
+ to render_template(partial: '_customer')
end
it 'rejects rendering a different template' do
- controller_with_customer_partial.
- should_not render_template(partial: '_client')
+ expect(controller_with_customer_partial).
+ not_to 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)
+ expect(controller_with_customer_partial).
+ to 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)
+ expect(controller_with_customer_partial).
+ not_to render_template(partial: '_client').in_context(self)
end
def controller_with_customer_partial
@@ -55,7 +55,7 @@ def controller_with_customer_partial
it 'accepts not rendering a partial' do
controller = build_response(action: 'show') { render }
- controller.should render_template(partial: false)
+ expect(controller).to render_template(partial: false)
end
end
@@ -65,14 +65,14 @@ def controller_with_customer_partial
render partial: 'customer', collection: [1,2]
end
- controller.should render_template(partial: '_customer', count: 2)
+ expect(controller).to render_template(partial: '_customer', count: 2)
end
end
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)
+ expect(build_response { render nothing: true }).
+ not_to render_template(:show)
end
end
end
View
12 spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb
@@ -5,15 +5,15 @@
context 'a controller that renders with a layout' do
it 'accepts rendering with any layout' do
- controller_with_wide_layout.should render_with_layout
+ expect(controller_with_wide_layout).to render_with_layout
end
it 'accepts rendering with that layout' do
- controller_with_wide_layout.should render_with_layout(:wide)
+ expect(controller_with_wide_layout).to render_with_layout(:wide)
end
it 'rejects rendering with another layout' do
- controller_with_wide_layout.should_not render_with_layout(:other)
+ expect(controller_with_wide_layout).not_to render_with_layout(:other)
end
def controller_with_wide_layout
@@ -27,7 +27,7 @@ def controller_with_wide_layout
it 'rejects rendering with a layout' do
controller_without_layout = build_response { render layout: false }
- controller_without_layout.should_not render_with_layout
+ expect(controller_without_layout).not_to render_with_layout
end
end
@@ -35,7 +35,7 @@ def controller_with_wide_layout
it 'rejects rendering with a layout' do
controller_with_partial = build_response { render partial: 'partial' }
- controller_with_partial.should_not render_with_layout
+ expect(controller_with_partial).not_to render_with_layout
end
end
@@ -43,7 +43,7 @@ def controller_with_wide_layout
it 'accepts that layout in that context' do
set_in_context_layout('happy')
- controller_without_layout.should render_with_layout('happy').in_context(self)
+ expect(controller_without_layout).to render_with_layout('happy').in_context(self)
end
def set_in_context_layout(layout)
View
18 spec/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb
@@ -3,30 +3,30 @@
describe Shoulda::Matchers::ActionController::RescueFromMatcher do
context 'a controller that rescues from RuntimeError' do
it "asserts controller is setup with rescue_from" do
- controller_with_rescue_from.should rescue_from RuntimeError
+ expect(controller_with_rescue_from).to rescue_from RuntimeError
end
context 'with a handler method' do
it "asserts rescue_from was set up with handler method" do
- controller_with_rescue_from_and_method.should rescue_from(RuntimeError).with(:error_method)
+ expect(controller_with_rescue_from_and_method).to rescue_from(RuntimeError).with(:error_method)
end
it "asserts rescue_from was not set up with incorrect handler method" do
- controller_with_rescue_from_and_method.should_not rescue_from(RuntimeError).with(:other_method)
+ expect(controller_with_rescue_from_and_method).not_to rescue_from(RuntimeError).with(:other_method)
end
it "asserts the controller responds to the handler method" do
matcher = rescue_from(RuntimeError).with(:error_method)
- matcher.matches?(controller_with_rescue_from_and_invalid_method).should be_false
- matcher.failure_message.should =~ /does not respond to/
+ expect(matcher.matches?(controller_with_rescue_from_and_invalid_method)).to eq false
+ expect(matcher.failure_message).to match(/does not respond to/)
end
end
context 'without a handler method' do
it "the handler method is not included in the description" do
matcher = rescue_from(RuntimeError)
- matcher.matches?(controller_with_rescue_from).should be_true
- matcher.description.should_not =~ /with #/
+ expect(matcher.matches?(controller_with_rescue_from)).to eq true
+ expect(matcher.description).not_to match(/with #/)
end
end
end
@@ -34,8 +34,8 @@
context 'a controller that does not rescue from RuntimeError' do
it "asserts controller is not setup with rescue_from" do
matcher = rescue_from RuntimeError
- define_controller("RandomController").should_not matcher
- matcher.failure_message_when_negated.should =~ /Did not expect \w+ to rescue from/
+ expect(define_controller("RandomController")).not_to matcher
+ expect(matcher.failure_message_when_negated).to match(/Did not expect \w+ to rescue from/)
end
end
View
8 spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb
@@ -7,18 +7,18 @@
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)
+ expect(controller_with_status(numeric_code)).to respond_with(numeric_code)
end
it 'accepts responding with a symbol response code' do
- controller_with_status(numeric_code).should respond_with(human_name)
+ expect(controller_with_status(numeric_code)).to respond_with(human_name)
end
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)
+ expect(controller_with_status(numeric_code)).
+ not_to respond_with(another_status)
end
end
end
View
20 spec/shoulda/matchers/action_controller/route_matcher_spec.rb
@@ -9,7 +9,7 @@
get 'examples/*id', to: 'examples#example'
end
- controller.should route(:get, '/examples/foo/bar').
+ expect(controller).to route(:get, '/examples/foo/bar').
to(action: 'example', id: 'foo/bar')
end
end
@@ -17,45 +17,45 @@
context 'given a controller with a defined route' do
it 'accepts routing the correct path to the correct parameters' do
- route_examples_to_examples.should route(:get, '/examples/1').
+ expect(route_examples_to_examples).to route(:get, '/examples/1').
to(action: 'example', id: '1')
end
it 'accepts a symbol controller' do
route_examples_to_examples
- Object.new.should route(:get, '/examples/1').
+ expect(Object.new).to route(:get, '/examples/1').
to(controller: :examples, action: 'example', id: '1')
end
it 'accepts a symbol action' do
- route_examples_to_examples.should route(:get, '/examples/1').
+ expect(route_examples_to_examples).to route(:get, '/examples/1').
to(action: :example, id: '1')
end
it 'accepts a non-string parameter' do
- route_examples_to_examples.should route(:get, '/examples/1').
+ expect(route_examples_to_examples).to route(:get, '/examples/1').
to(action: 'example', id: 1)
end
it 'rejects an undefined route' do
- route_examples_to_examples.
- should_not route(:get, '/bad_route').to(var: 'value')
+ expect(route_examples_to_examples).
+ not_to route(:get, '/bad_route').to(var: 'value')
end
it 'rejects a route for another controller' do
route_examples_to_examples
other = define_controller('Other').new
- other.should_not route(:get, '/examples/1').
+ expect(other).not_to route(:get, '/examples/1').
to(action: 'example', id: '1')
end
it 'rejects a route for different parameters' do
- route_examples_to_examples.should_not route(:get, '/examples/1').
+ expect(route_examples_to_examples).not_to route(:get, '/examples/1').
to(action: 'other', id: '1')
end
it "accepts a string as first parameter" do
- route_examples_to_examples.should route(:get, '/examples/1').
+ expect(route_examples_to_examples).to route(:get, '/examples/1').
to("examples#example", id: '1')
end
View
12 spec/shoulda/matchers/action_controller/route_params_spec.rb
@@ -4,22 +4,22 @@
describe "#normalize" do
context "when the route parameters is a hash" do
it "stringifies the values in the hash" do
- build_route_params(controller: :examples, action: 'example', id: '1').normalize.
- should eq({ controller: "examples", action: "example", id: "1" })
+ expect(build_route_params(controller: :examples, action: 'example', id: '1').normalize).
+ to eq({ controller: "examples", action: "example", id: "1" })
end
end
context "when the route parameters is a string and a hash" do
it "produces a hash of route parameters" do
- build_route_params("examples#example", id: '1').normalize.
- should eq({ controller: "examples", action: "example", id: "1" })
+ expect(build_route_params("examples#example", id: '1').normalize).
+ to eq({ controller: "examples", action: "example", id: "1" })
end
end
context "when the route params is a string" do
it "produces a hash of route params" do
- build_route_params("examples#index").normalize.
- should eq({ controller: "examples", action: "index"})
+ expect(build_route_params("examples#index").normalize).
+ to eq({ controller: "examples", action: "index"})
end
end
end
View
20 spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
@@ -3,41 +3,41 @@
describe Shoulda::Matchers::ActionController::SetSessionMatcher do
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)
+ expect(controller_with_session(var: 'hi')).to set_session(:var)
end
it 'accepts assigning the correct value to that variable' do
- controller_with_session(var: 'hi').should set_session(:var).to('hi')
+ expect(controller_with_session(var: 'hi')).to set_session(:var).to('hi')
end
it 'rejects assigning another value to that variable' do
- controller_with_session(var: 'hi').should_not set_session(:var).to('other')
+ expect(controller_with_session(var: 'hi')).not_to set_session(:var).to('other')
end
it 'rejects assigning to another variable' do
- controller_with_session(var: 'hi').should_not set_session(:other)
+ expect(controller_with_session(var: 'hi')).not_to set_session(:other)
end
it 'accepts assigning nil to another variable' do
- controller_with_session(var: 'hi').should set_session(:other).to(nil)
+ expect(controller_with_session(var: 'hi')).to set_session(:other).to(nil)
end
it 'accepts assigning false to that variable' do
- controller_with_session(var: false).should set_session(:var).to(false)
+ expect(controller_with_session(var: false)).to set_session(:var).to(false)
end
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 }
+ expect(controller_with_session(var: expected)).
+ to 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 }
+ expect(controller_with_session(var: 'unexpected')).
+ not_to set_session(:var).in_context(self).to { expected }
end
def controller_with_session(session_hash)
View
72 spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb
@@ -7,55 +7,55 @@
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
+ expect(controller_with_flash(notice: 'hi')).to set_the_flash
end
it 'accepts setting the exact flash message' do
- controller_with_flash(notice: 'hi').should set_the_flash.to('hi')
+ expect(controller_with_flash(notice: 'hi')).to set_the_flash.to('hi')
end
it 'accepts setting a matched flash message' do
- controller_with_flash(notice: 'hello').should set_the_flash.to(/he/)
+ expect(controller_with_flash(notice: 'hello')).to set_the_flash.to(/he/)
end
it 'rejects setting a different flash message' do
- controller_with_flash(notice: 'hi').
- should_not set_the_flash.to('other')
+ expect(controller_with_flash(notice: 'hi')).
+ not_to 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/)
+ expect(controller_with_flash(notice: 'hi')).
+ not_to set_the_flash.to(/other/)
end
end
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
+ expect(controller_with_flash_now).not_to set_the_flash
end
it 'accepts setting any flash.now message' do
- controller_with_flash_now.should set_the_flash.now
+ expect(controller_with_flash_now).to set_the_flash.now
end
it 'accepts setting the exact flash.now message' do
- controller_with_flash_now(notice: 'hi').
- should set_the_flash.now.to('hi')
+ expect(controller_with_flash_now(notice: 'hi')).
+ to 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/)
+ expect(controller_with_flash_now(notice: 'flasher')).
+ to 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')
+ expect(controller_with_flash_now(notice: 'hi')).
+ not_to 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/)
+ expect(controller_with_flash_now(notice: 'hi')).
+ not_to set_the_flash.now.to(/other/)
end
end
@@ -63,33 +63,33 @@
it 'accepts flash message for either key' do
controller = controller_with_flash(notice: 'one', alert: 'two')
- controller.should set_the_flash[:notice]
- controller.should set_the_flash[:alert]
+ expect(controller).to set_the_flash[:notice]
+ expect(controller).to set_the_flash[:alert]
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]
+ expect(controller_with_flash(notice: 'one', alert: 'two')).
+ not_to 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')
+ expect(controller_with_flash(notice: 'one', alert: 'two')).
+ to 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/)
+ expect(controller_with_flash(notice: 'one', alert: 'two')).
+ to 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')
+ expect(controller_with_flash(notice: 'one', alert: 'two')).
+ not_to 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/)
+ expect(controller_with_flash(notice: 'one', alert: 'two')).
+ not_to set_the_flash[:notice].to(/other/)
end
end
@@ -100,8 +100,8 @@
flash[:success] = 'great job'
end
- controller.should set_the_flash.now
- controller.should set_the_flash
+ expect(controller).to set_the_flash.now
+ expect(controller).to set_the_flash
end
it 'accepts setting a matched flash.now message' do
@@ -110,8 +110,8 @@
flash[:success] = 'great job'
end
- controller.should set_the_flash.now.to(/value/)
- controller.should set_the_flash.to(/great/)
+ expect(controller).to set_the_flash.now.to(/value/)
+ expect(controller).to set_the_flash.to(/great/)
end
it 'rejects setting a different flash.now message' do
@@ -120,14 +120,14 @@
flash[:success] = 'great job'
end
- controller.should_not set_the_flash.now.to('other')
- controller.should_not set_the_flash.to('other')
+ expect(controller).not_to set_the_flash.now.to('other')
+ expect(controller).not_to set_the_flash.to('other')
end
end
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
+ expect(controller_with_no_flashes).not_to set_the_flash
end
end
View
30 spec/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb
@@ -4,16 +4,16 @@
context '#description' do
context 'without a role' do
it 'includes the attribute name' do
- described_class.new(:attr).description.
- should eq 'allow mass assignment of attr'
+ expect(described_class.new(:attr).description).
+ to eq 'allow mass assignment of attr'
end
end
if active_model_3_1?
context 'with a role' do
it 'includes the attribute name and the role' do
- described_class.new(:attr).as(:admin).description.
- should eq 'allow mass assignment of attr as admin'
+ expect(described_class.new(:attr).as(:admin).description).
+ to eq 'allow mass assignment of attr as admin'
end
end
end
@@ -25,7 +25,7 @@
attr_protected :blacklisted
end.new
- model.should_not allow_mass_assignment_of(:blacklisted)
+ expect(model).not_to allow_mass_assignment_of(:blacklisted)
end
end
@@ -36,15 +36,15 @@
attr_accessible :whitelisted
end.new
- model.should_not allow_mass_assignment_of(:not_whitelisted)
+ expect(model).not_to allow_mass_assignment_of(:not_whitelisted)
end
end
context 'an attribute that is whitelisted for mass-assignment' do
it 'accepts being mass-assignable' do
- define_model(:example, whitelisted: :string) do
+ expect(define_model(:example, whitelisted: :string) do
attr_accessible :whitelisted
- end.new.should allow_mass_assignment_of(:whitelisted)
+ end.new).to allow_mass_assignment_of(:whitelisted)
end
end
@@ -55,22 +55,22 @@
attr_protected :blacklisted
end.new
- model.should allow_mass_assignment_of(:not_blacklisted)
+ expect(model).to allow_mass_assignment_of(:not_blacklisted)
end
end
unless active_model_3_2? || active_model_4_0?
context 'an attribute on a class with no protected attributes' do
it 'accepts being mass-assignable' do
- no_protected_attributes.should allow_mass_assignment_of(:attr)
+ expect(no_protected_attributes).to allow_mass_assignment_of(:attr)
end
it 'assigns a negative failure message' do
matcher = allow_mass_assignment_of(:attr)
- matcher.matches?(no_protected_attributes).should be_true
+ expect(matcher.matches?(no_protected_attributes)).to eq true
- matcher.failure_message_when_negated.should_not be_nil
+ expect(matcher.failure_message_when_negated).not_to be_nil
end
end
@@ -81,7 +81,7 @@ def no_protected_attributes
context 'an attribute on a class with all protected attributes' do
it 'rejects being mass-assignable' do
- all_protected_attributes.should_not allow_mass_assignment_of(:attr)
+ expect(all_protected_attributes).not_to allow_mass_assignment_of(:attr)
end
def all_protected_attributes
@@ -94,11 +94,11 @@ def all_protected_attributes
if active_model_3_1?
context 'an attribute included in the mass-assignment whitelist for admin role only' do
it 'rejects being mass-assignable' do
- mass_assignable_as_admin.should_not allow_mass_assignment_of(:attr)
+ expect(mass_assignable_as_admin).not_to allow_mass_assignment_of(:attr)
end
it 'accepts being mass-assignable for admin' do
- mass_assignable_as_admin.should allow_mass_assignment_of(:attr).as(:admin)
+ expect(mass_assignable_as_admin).to allow_mass_assignment_of(:attr).as(:admin)
end
def mass_assignable_as_admin
View
56 spec/shoulda/matchers/active_model/allow_value_matcher_spec.rb
@@ -5,65 +5,65 @@
it 'describes itself with multiple values' do
matcher = allow_value('foo', 'bar').for(:baz)
- matcher.description.should eq 'allow baz to be set to any of ["foo", "bar"]'
+ expect(matcher.description).to eq 'allow baz to be set to any of ["foo", "bar"]'
end
it 'describes itself with a single value' do
matcher = allow_value('foo').for(:baz)
- matcher.description.should eq 'allow baz to be set to "foo"'
+ expect(matcher.description).to eq 'allow baz to be set to "foo"'
end
if active_model_3_2?
it 'describes itself with a strict validation' do
strict_matcher = allow_value('xyz').for(:attr).strict
- strict_matcher.description.
- should eq %q(doesn't raise when attr is set to "xyz")
+ expect(strict_matcher.description).
+ to eq %q(doesn't raise when attr is set to "xyz")
end
end
end
context 'an attribute with a validation' do
it 'allows a good value' do
- validating_format(with: /abc/).should allow_value('abcde').for(:attr)
+ expect(validating_format(with: /abc/)).to allow_value('abcde').for(:attr)
end
it 'rejects a bad value' do
- validating_format(with: /abc/).should_not allow_value('xyz').for(:attr)
+ expect(validating_format(with: /abc/)).not_to allow_value('xyz').for(:attr)
end
it 'allows several good values' do
- validating_format(with: /abc/).
- should allow_value('abcde', 'deabc').for(:attr)
+ expect(validating_format(with: /abc/)).
+ to 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)
+ expect(validating_format(with: /abc/)).
+ not_to 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/)
+ expect(validating_format(with: /abc/, message: 'bad value')).
+ to 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/)
+ expect(validating_format(with: /abc/, message: 'bad value')).
+ not_to allow_value('xyz').for(:attr).with_message(/bad/)
end
end
context 'an attribute where the message occurs on another attribute' do
it 'allows a good value' do
- record_with_custom_validation.should \
+ expect(record_with_custom_validation).to \
allow_value('good value').for(:attr).with_message(/some message/, against: :attr2)
end
it 'rejects a bad value' do
- record_with_custom_validation.should_not \
+ expect(record_with_custom_validation).not_to \
allow_value('bad value').for(:attr).with_message(/some message/, against: :attr2)
end
@@ -83,17 +83,17 @@ def custom_validation
context "an attribute with a context-dependent validation" do
context "without the validation context" do
it "allows a bad value" do
- validating_format(with: /abc/, on: :customisable).should allow_value("xyz").for(:attr)
+ expect(validating_format(with: /abc/, on: :customisable)).to allow_value("xyz").for(:attr)
end
end
context "with the validation context" do
it "allows a good value" do
- validating_format(with: /abc/, on: :customisable).should allow_value("abcde").for(:attr).on(:customisable)
+ expect(validating_format(with: /abc/, on: :customisable)).to allow_value("abcde").for(:attr).on(:customisable)
end
it "rejects a bad value" do
- validating_format(with: /abc/, on: :customisable).should_not allow_value("xyz").for(:attr).on(:customisable)
+ expect(validating_format(with: /abc/, on: :customisable)).not_to allow_value("xyz").for(:attr).on(:customisable)
end
end
end
@@ -110,21 +110,21 @@ def custom_validation
bad_values = [nil, '', 'abc', '0', '50001', '123456', []]
it 'allows a good value' do
- model.should allow_value('12345').for(:attr)
+ expect(model).to allow_value('12345').for(:attr)
end
bad_values.each do |bad_value|
it "rejects a bad value (#{bad_value.inspect})" do
- model.should_not allow_value(bad_value).for(:attr)
+ expect(model).not_to allow_value(bad_value).for(:attr)
end
end
it "rejects several bad values (#{bad_values.map(&:inspect).join(', ')})" do
- model.should_not allow_value(*bad_values).for(:attr)
+ expect(model).not_to allow_value(*bad_values).for(:attr)
end
it "rejects a mix of both good and bad values" do
- model.should_not allow_value('12345', *bad_values).for(:attr)
+ expect(model).not_to allow_value('12345', *bad_values).for(:attr)
end
end
@@ -148,13 +148,13 @@ def custom_validation
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
+ expect(validating_format(with: /abc/, strict: true)).
+ not_to 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
+ expect(validating_format(with: /abc/, strict: true)).
+ to allow_value('xyz').for(:attr).with_message(/abc/).strict
end
it 'provides a useful negative failure message' do
@@ -162,7 +162,7 @@ def custom_validation
matcher.matches?(validating_format(with: /abc/, strict: true))
- matcher.failure_message_when_negated.should eq 'Expected exception to include /abc/ ' +
+ expect(matcher.failure_message_when_negated).to eq 'Expected exception to include /abc/ ' +
'when attr is set to "xyz", got Attr is invalid'
end
end
View
26 spec/shoulda/matchers/active_model/disallow_value_matcher_spec.rb
@@ -2,41 +2,41 @@
describe Shoulda::Matchers::ActiveModel::DisallowValueMatcher do
it 'does not allow any types' do
- matcher('abcde').allowed_types.should eq ''
+ expect(matcher('abcde').allowed_types).to eq ''
end
context 'an attribute with a format validation' do
it 'does not match if the value is allowed' do
- validating_format(with: /abc/).should_not matcher('abcde').for(:attr)
+ expect(validating_format(with: /abc/)).not_to matcher('abcde').for(:attr)
end
it 'matches if the value is not allowed' do
- validating_format(with: /abc/).should matcher('xyz').for(:attr)
+ expect(validating_format(with: /abc/)).to matcher('xyz').for(:attr)
end
end
context "an attribute with a context-dependent validation" do
context "without the validation context" do
it "does not match" do
- validating_format(with: /abc/, on: :customisable).should_not matcher("xyz").for(:attr)
+ expect(validating_format(with: /abc/, on: :customisable)).not_to matcher("xyz").for(:attr)
end
end
context "with the validation context" do
it "disallows a bad value" do
- validating_format(with: /abc/, on: :customisable).should matcher("xyz").for(:attr).on(:customisable)
+ expect(validating_format(with: /abc/, on: :customisable)).to matcher("xyz").for(:attr).on(:customisable)
end
it "does not match a good value" do
- validating_format(with: /abc/, on: :customisable).should_not matcher("abcde").for(:attr).on(:customisable)
+ expect(validating_format(with: /abc/, on: :customisable)).not_to matcher("abcde").for(:attr).on(:customisable)
end
end
end
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')
+ expect(validating_format(with: /abc/, message: 'good message')).
+ not_to matcher('abcde').for(:attr).with_message('good message')
end
it "delegates its failure message to its allow matcher's negative failure message" do
@@ -46,23 +46,23 @@
matcher = matcher('abcde').for(:attr).with_message('good message')
matcher.matches?(validating_format(with: /abc/, message: 'good message'))
- matcher.failure_message.should eq 'allow matcher failure'
+ expect(matcher.failure_message).to eq 'allow matcher failure'
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')
+ expect(validating_format(with: /abc/, message: 'good message')).
+ to matcher('xyz').for(:attr).with_message('good message')
end
end
context 'an attribute where the message occurs on another attribute' do
it 'matches if the message is correct but the value is not' do
- record_with_custom_validation.should \
+ expect(record_with_custom_validation).to \
matcher('bad value').for(:attr).with_message(/some message/, against: :attr2)
end
it 'does not match if the value and message are both correct' do
- record_with_custom_validation.should_not \
+ expect(record_with_custom_validation).not_to \
matcher('good value').for(:attr).with_message(/some message/, against: :attr2)
end
View
44 spec/shoulda/matchers/active_model/ensure_exclusion_of_matcher_spec.rb
@@ -3,37 +3,37 @@
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)
+ expect(validating_exclusion(in: 2..5)).
+ to 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)
+ expect(validating_exclusion(in: 2..5)).
+ not_to 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)
+ expect(validating_exclusion(in: 2..5)).
+ to ensure_exclusion_of(:attr).in_range(2..5).with_message(nil)
end
end
context 'an attribute which must be excluded from a range with excluded end' do
it 'accepts ensuring the correct range' do
- validating_exclusion(in: 2...5).
- should ensure_exclusion_of(:attr).in_range(2...5)
+ expect(validating_exclusion(in: 2...5)).
+ to 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...4)
+ expect(validating_exclusion(in: 2...5)).
+ not_to ensure_exclusion_of(:attr).in_range(2...4)
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/)
+ expect(validating_exclusion(in: 2..4, message: 'not good')).
+ to ensure_exclusion_of(:attr).in_range(2..4).with_message(/not good/)
end
end
@@ -45,7 +45,7 @@
end
end
- model.should ensure_exclusion_of(:attr).in_range(2..5).
+ expect(model).to ensure_exclusion_of(:attr).in_range(2..5).
with_message(/should be out of this range/)
model = custom_validation do
@@ -54,30 +54,30 @@
end
end
- model.should ensure_exclusion_of(:attr).in_range(2...5).
+ expect(model).to ensure_exclusion_of(:attr).in_range(2...5).
with_message(/should be out of this range/)
end
end
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))
+ expect(validating_exclusion(in: %w(one two))).
+ to 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))
+ expect(validating_exclusion(in: %w(one two))).
+ not_to 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))
+ expect(validating_exclusion(in: %w(one two))).
+ not_to 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 eq 'ensure exclusion of attr in [true, "dog"]'
+ expect(ensure_exclusion_of(:attr).in_array([true, 'dog']).description).
+ to eq 'ensure exclusion of attr in [true, "dog"]'
end
def validating_exclusion(options)
View
114 spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb
@@ -3,8 +3,8 @@
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))
+ expect(define_model(:example, attr: :string).new).
+ not_to ensure_inclusion_of(:attr).in_array(%w(Yes No))
end
end
@@ -14,7 +14,7 @@
validates_inclusion_of :attr, in: [0, 1, 2]
end.new
- model.should ensure_inclusion_of(:attr).in_array([0,1,2])
+ expect(model).to ensure_inclusion_of(:attr).in_array([0,1,2])
end
end
@@ -24,14 +24,14 @@
validates_inclusion_of :attr, in: [0.0, 0.1]
end.new
- model.should ensure_inclusion_of(:attr).in_array([0.0, 0.1])
+ expect(model).to ensure_inclusion_of(:attr).in_array([0.0, 0.1])
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])
+ expect(define_model(:example, attr: :string).new).
+ not_to ensure_inclusion_of(:attr).in_array([true, false])
end
end
@@ -40,58 +40,58 @@
model = define_model(:example, attr: :string).new
arbitrary_string = described_class::ARBITRARY_OUTSIDE_STRING
- expect { model.should ensure_inclusion_of(:attr).in_array([arbitrary_string]) }.to raise_error Shoulda::Matchers::ActiveModel::CouldNotDetermineValueOutsideOfArray
+ expect { expect(model).to ensure_inclusion_of(:attr).in_array([arbitrary_string]) }.to raise_error Shoulda::Matchers::ActiveModel::CouldNotDetermineValueOutsideOfArray
end
end
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)
+ expect(validating_inclusion(in: 2..5)).
+ to 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)
+ expect(validating_inclusion(in: 2..5)).
+ not_to 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)
+ expect(validating_inclusion(in: 2..5)).
+ not_to 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)
+ expect(validating_inclusion(in: 2..5)).
+ not_to 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)
+ expect(validating_inclusion(in: 2..5)).
+ not_to 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)
+ expect(validating_inclusion(in: 2..5)).
+ to ensure_inclusion_of(:attr).in_range(2..5).with_message(nil)
end
end
context 'an attribute which must be included in a range with excluded end' do
it 'accepts ensuring the correct range' do
- validating_inclusion(in: 2...5).
- should ensure_inclusion_of(:attr).in_range(2...5)
+ expect(validating_inclusion(in: 2...5)).
+ to ensure_inclusion_of(:attr).in_range(2...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)
+ expect(validating_inclusion(in: 2...5)).
+ not_to ensure_inclusion_of(:attr).in_range(2...4)
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/)
+ expect(validating_inclusion(in: 2..4, message: 'not good')).
+ to ensure_inclusion_of(:attr).in_range(2..4).with_message(/not good/)
end
end
@@ -105,7 +105,7 @@
end
end
- model.should ensure_inclusion_of(:attr).in_range(2..5).
+ expect(model).to ensure_inclusion_of(:attr).in_range(2..5).
with_low_message(/low/).with_high_message(/high/)
model = custom_validation do
@@ -116,92 +116,92 @@
end
end
- model.should ensure_inclusion_of(:attr).in_range(2...5).
+ expect(model).to ensure_inclusion_of(:attr).in_range(2...5).
with_low_message(/low/).with_high_message(/high/)
end
end
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))
+ expect(validating_inclusion(in: %w(one two))).
+ to 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))
+ expect(validating_inclusion(in: %w(one two))).
+ not_to 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))
+ expect(validating_inclusion(in: %w(one two))).
+ not_to 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 eq 'ensure inclusion of attr in [true, "dog"]'
+ expect(ensure_inclusion_of(:attr).in_array([true, "dog"]).description).
+ to eq '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)
+ expect(validating_inclusion(in: %w(one two))).
+ not_to 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)
+ expect(validating_inclusion(in: %w(one two))).
+ to 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)
+ expect(validating_inclusion(in: %w(one two))).
+ not_to 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)
+ expect(validating_inclusion(in: %w(one two))).
+ to ensure_inclusion_of(:attr).in_array(%w(one two)).allow_nil(false)
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
+ expect(validating_inclusion(in: %w(one two), allow_blank: true)).
+ to 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)
+ expect(validating_inclusion(in: %w(one two), allow_blank: true)).
+ not_to 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
+ expect(validating_inclusion(in: %w(one two), allow_nil: true)).
+ to 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)
+ expect(validating_inclusion(in: %w(one two), allow_nil: true)).
+ not_to ensure_inclusion_of(:attr).in_array(%w(one two)).allow_nil(false)
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)
+ expect(validating_inclusion(in: ['one', 'two', ''])).
+ not_to ensure_inclusion_of(:attr).in_array(['one', 'two', '']).allow_blank(true)
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
+ expect(validating_inclusion(in: 2..5, strict: true)).
+ to 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
+ expect(validating_inclusion(in: 2..5, strict: true)).
+ not_to ensure_inclusion_of(:attr).in_range(2..6).strict
end
end
end
View
74 spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb
@@ -3,73 +3,73 @@
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)
+ expect(validating_length(minimum: 4)).
+ to 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(/.*/)
+ expect(validating_length(minimum: 4)).
+ not_to 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(/.*/)
+ expect(validating_length(minimum: 4)).
+ not_to 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)
+ expect(validating_length(minimum: 4)).
+ to 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)
+ expect(validating_length(minimum: 0)).
+ to 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)
+ expect(validating_length(maximum: 4)).
+ to 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(/.*/)
+ expect(validating_length(maximum: 4)).
+ not_to 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(/.*/)
+ expect(validating_length(maximum: 4)).
+ not_to 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)
+ expect(validating_length(maximum: 4)).
+ to ensure_length_of(:attr).is_at_most(4).with_long_message(nil)
end
end
context 'an attribute with a required exact length' do
it 'accepts ensuring the correct length' do
- validating_length(is: 4).should ensure_length_of(:attr).is_equal_to(4)
+ expect(validating_length(is: 4)).to ensure_length_of(:attr).is_equal_to(4)
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(/.*/)
+ expect(validating_length(is: 4)).
+ not_to 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(/.*/)
+ expect(validating_length(is: 4)).
+ not_to 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)
+ expect(validating_length(is: 4)).
+ to ensure_length_of(:attr).is_equal_to(4).with_message(nil)
end
end
@@ -80,35 +80,35 @@
validates_numericality_of :attr
end.new
- model.should ensure_length_of(:attr).is_equal_to(4)
+ expect(model).to ensure_length_of(:attr).is_equal_to(4)
end
end
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/)
+ expect(validating_length(minimum: 4, too_short: 'foobar')).
+ to 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/)
+ expect(validating_length(maximum: 4, too_long: 'foobar')).
+ to ensure_length_of(:attr).is_at_most(4).with_long_message(/foo/)
end
end
context 'an attribute with a custom equal validation' do
it 'accepts ensuring the correct exact length' do
- validating_length(is: 4, message: 'foobar').
- should ensure_length_of(:attr).is_equal_to(4).with_message(/foo/)
+ expect(validating_length(is: 4, message: 'foobar')).
+ to ensure_length_of(:attr).is_equal_to(4).with_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)
+ expect(define_model(:example, attr: :string).new).
+ not_to ensure_length_of(:attr).is_at_least(1)
end
end
@@ -124,7 +124,7 @@
it "does not raise an exception" do
expect {
- validating_length(maximum: 4).should ensure_length_of(:attr).is_at_most(4)
+ expect(validating_length(maximum: 4)).to ensure_length_of(:attr).is_at_most(4)
}.to_not raise_exception
end
end
@@ -138,7 +138,7 @@
it "does not raise an exception" do
expect {
- validating_length(minimum: 4).should ensure_length_of(:attr).is_at_least(4)
+ expect(validating_length(minimum: 4)).to ensure_length_of(:attr).is_at_least(4)
}.to_not raise_exception
end
end
@@ -152,7 +152,7 @@
it "does not raise an exception" do
expect {
- validating_length(is: 4).should ensure_length_of(:attr).is_equal_to(4)
+ expect(validating_length(is: 4)).to ensure_length_of(:attr).is_equal_to(4)
}.to_not raise_exception
end
end
View
16 spec/shoulda/matchers/active_model/exception_message_finder_spec.rb
@@ -8,7 +8,7 @@
description = finder.allow_description('allowed values')
- description.should eq %q(doesn't raise when attr is set to allowed values)
+ expect(description).to eq %q(doesn't raise when attr is set to allowed values)
end
end
@@ -18,7 +18,7 @@
message = finder.expected_message_from('some message')
- message.should eq 'Attr some message'
+ expect(message).to eq 'Attr some message'
end
end
@@ -28,7 +28,7 @@
result = finder.has_messages?
- result.should be_true
+ expect(result).to eq true
end
it 'has no messages when all validations pass' do
@@ -36,7 +36,7 @@
result = finder.has_messages?
- result.should be_false
+ expect(result).to eq false
end
end
@@ -50,7 +50,7 @@
messages = finder.messages
- messages.should eq ['Attr is invalid']
+ expect(messages).to eq ['Attr is invalid']
end
end
@@ -64,7 +64,7 @@
description = finder.messages_description
- description.should eq 'Attr is invalid'
+ expect(description).to eq 'Attr is invalid'
end
it 'describes errors when there are none' do
@@ -72,7 +72,7 @@
description = finder.messages_description
- description.should eq 'no exception'
+ expect(description).to eq 'no exception'
end
end
@@ -82,7 +82,7 @@
description = finder.source_description
- description.should eq 'exception'
+ expect(description).to eq 'exception'
end
end
end
View
10 spec/shoulda/matchers/active_model/helpers_spec.rb
@@ -88,15 +88,17 @@
end
def assert_presence_validation_has_correct_message
- define_model :example, attr: :string do
+ record = define_model :example, attr: :string do
validates_presence_of :attr
- end.new.should validate_presence_of(:attr)
+ end.new
+ expect(record).to validate_presence_of(:attr)
end
def assert_length_validation_has_correct_message
- define_model :example, attr: :string do
+ record = define_model :example, attr: :string do
validates_length_of :attr, is: 40, allow_blank: true
- end.new.should ensure_length_of(:attr).is_equal_to(40)
+ end.new
+ expect(record).to ensure_length_of(:attr).is_equal_to(40)
end
def store_translations(options = {without: []})
View
22 spec/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb
@@ -6,34 +6,34 @@
end
context 'is_greater_than' do
- it { instance_with_validations(greater_than: 2).should matcher.is_greater_than(2) }
- it { instance_without_validations.should_not matcher.is_greater_than(2) }
+ it { expect(instance_with_validations(greater_than: 2)).to matcher.is_greater_than(2) }
+ it { expect(instance_without_validations).not_to matcher.is_greater_than(2) }
end
context 'greater_than_or_equal_to' do
- it { instance_with_validations(greater_than_or_equal_to: 2).should matcher.is_greater_than_or_equal_to(2) }
- it { instance_without_validations.should_not matcher.is_greater_than_or_equal_to(2) }
+ it { expect(instance_with_validations(greater_than_or_equal_to: 2)).to matcher.is_greater_than_or_equal_to(2) }
+ it { expect(instance_without_validations).not_to matcher.is_greater_than_or_equal_to(2) }
end
context 'less_than' do
- it { instance_with_validations(less_than: 2).should matcher.is_less_than(2) }
- it { instance_without_validations.should_not matcher.is_less_than(2) }
+ it { expect(instance_with_validations(less_than: 2)).to matcher.is_less_than(2) }
+ it { expect(instance_without_validations).not_to matcher.is_less_than(2) }
end
context 'less_than_or_equal_to' do
- it { instance_with_validations(less_than_or_equal_to: 2).should matcher.is_less_than_or_equal_to(2) }
- it { instance_without_validations.should_not matcher.is_less_than_or_equal_to(2) }
+ it { expect(instance_with_validations(less_than_or_equal_to: 2)).to matcher.is_less_than_or_equal_to(2) }
+ it { expect(instance_without_validations).not_to matcher.is_less_than_or_equal_to(2) }
end
context 'is_equal_to' do
- it { instance_with_validations(equal_to: 0).should matcher.is_equal_to(0) }
- it { instance_without_validations.should_not matcher.is_equal_to(0) }
+ it { expect(instance_with_validations(equal_to: 0)).to matcher.is_equal_to(0) }
+ it { expect(instance_without_validations).not_to matcher.is_equal_to(0) }
end
context 'with_message' do
it 'verifies the message for the validation' do
instance = instance_with_validations(equal_to: 0, message: 'Must be zero')
- instance.should matcher.is_equal_to(0).with_message('Must be zero')
+ expect(instance).to matcher.is_equal_to(0).with_message('Must be zero')
end
end
View
24 spec/shoulda/matchers/active_model/numericality_matchers/odd_even_number_matcher_spec.rb
@@ -7,49 +7,49 @@
context 'given an attribute that only allows odd number values' do
it 'matches' do
- validating_odd_number.should new_odd_matcher
+ expect(validating_odd_number).to new_odd_matcher
end
it 'returns itself when given a message' do
matcher = new_odd_matcher
- matcher.with_message('some message').should eq matcher
+ expect(matcher.with_message('some message')).to eq matcher
end
end
context 'given an attribute that only allows even number values' do
it 'matches' do
- validating_even_number.should new_even_matcher
+ expect(validating_even_number).to new_even_matcher
end
it 'returns itself when given a message' do
matcher = new_even_matcher
- matcher.with_message('some message').should eq matcher
+ expect(matcher.with_message('some message')).to eq matcher
end
end
context 'given an attribute that only allows odd number values with a custom validation message' do
it 'only accepts odd number values for that attribute with that message' do
- validating_odd_number(message: 'custom').should new_odd_matcher.with_message(/custom/)
+ expect(validating_odd_number(message: 'custom')).to new_odd_matcher.with_message(/custom/)
end
it 'rejects odd number values for that attribute with another message' do
- validating_odd_number(message: 'custom').should_not new_odd_matcher.with_message(/wrong/)
+ expect(validating_odd_number(message: 'custom')).not_to new_odd_matcher.with_message(/wrong/)
end
end
context 'given an attribute that only allows even number values with a custom validation message' do
it 'only accepts even number values for that attribute with that message' do
- validating_even_number(message: 'custom').should new_even_matcher.with_message(/custom/)
+ expect(validating_even_number(message: 'custom')).to new_even_matcher.with_message(/custom/)
end
it 'rejects even number values for that attribute with another message' do
- validating_even_number(message: 'custom').should_not new_even_matcher.with_message(/wrong/)
+ expect(validating_even_number(message: 'custom')).not_to new_even_matcher.with_message(/wrong/)
end
end
context 'when the model does not have an odd validation' do
it 'does not match' do
- define_model(:example, attr: :string).new.should_not new_odd_matcher
+ expect(define_model(:example, attr: :string).new).not_to new_odd_matcher
end
it 'fails with the ActiveRecord :odd message' do
@@ -57,13 +57,13 @@
matcher.matches?(define_model(:example, attr: :string).new)
- matcher.failure_message.should include 'Expected errors to include "must be odd"'
+ expect(matcher.failure_message).to include 'Expected errors to include "must be odd"'
end
end
context 'when the model does not have an even validation' do
it 'does not match' do
- define_model(:example, attr: :string).new.should_not new_even_matcher
+ expect(define_model(:example, attr: :string).new).not_to new_even_matcher
end
it 'fails with the ActiveRecord :even message' do
@@ -71,7 +71,7 @@
matcher.matches?(define_model(:example, attr: :string).new)
- matcher.failure_message.should include 'Expected errors to include "must be even"'
+ expect(matcher.failure_message).to include 'Expected errors to include "must be even"'
end
end
View
14 spec/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb
@@ -7,32 +7,32 @@
context 'given an attribute that only allows integer values' do
it 'matches' do
- validating_only_integer.should new_matcher
+ expect(validating_only_integer).to new_matcher
end
it 'allows integer types' do
- new_matcher.allowed_types.should eq 'integer'
+ expect(new_matcher.allowed_types).to eq 'integer'
end
it 'returns itself when given a message' do
matcher = new_matcher
- matcher.with_message('some message').should eq matcher
+ expect(matcher.with_message('some message')).to eq matcher
end
end
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
- validating_only_integer(message: 'custom').should new_matcher.with_message(/custom/)
+ expect(validating_only_integer(message: 'custom')).to new_matcher.with_message(/custom/)
end
it 'rejects integer values for that attribute with another message' do
- validating_only_integer(message: 'custom').should_not new_matcher.with_message(/wrong/)
+ expect(validating_only_integer(message: 'custom')).not_to new_matcher.with_message(/wrong/)
end
end
context 'when the model does not have an only_integer validation' do
it 'does not match' do
- define_model(:example, attr: :string).new.should_not new_matcher
+ expect(define_model(:example, attr: :string).new).not_to new_matcher
end
it 'fails with the ActiveRecord :not_an_integer message' do
@@ -40,7 +40,7 @@
matcher.matches?(define_model(:example, attr: :string).new)
- matcher.failure_message.should include 'Expected errors to include "must be an integer"'
+ expect(matcher.failure_message).to include 'Expected errors to include "must be an integer"'
end
end
View
30 spec/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb
@@ -4,67 +4,67 @@
if active_model_4_0?
context 'a model with an absence validation' do
it 'accepts' do
- validating_absence_of(:attr).should validate_absence_of(:attr)
+ expect(validating_absence_of(:attr)).to validate_absence_of(:attr)
end
it 'does not override the default message with a present' do
- validating_absence_of(:attr).should validate_absence_of(:attr).with_message(nil)
+ expect(validating_absence_of(:attr)).to validate_absence_of(:attr).with_message(nil)
end
end
context 'a model without an absence validation' do
it 'rejects' do
model = define_model(:example, attr: :string).new
- model.should_not validate_absence_of(:attr)
+ expect(model).not_to validate_absence_of(:attr)
end
end
context 'an ActiveModel class with an absence validation' do
it 'accepts' do
- active_model_validating_absence_of(:attr).should validate_absence_of(:attr)
+ expect(active_model_validating_absence_of(:attr)).to validate_absence_of(:attr)
end
it 'does not override the default message with a blank' do
- active_model_validating_absence_of(:attr).should validate_absence_of(:attr).with_message(nil)
+ expect(active_model_validating_absence_of(:attr)).to validate_absence_of(:attr).with_message(nil)
end
end
context 'an ActiveModel class without an absence validation' do
it 'rejects' do
- active_model_with(:attr).should_not validate_absence_of(:attr)
+ expect(active_model_with(:attr)).not_to validate_absence_of(:attr)
end
it 'provides the correct failure message' do
message = %{Expected errors to include "must be blank" when attr is set to "an arbitrary value", got no errors}
- expect { active_model_with(:attr).should validate_absence_of(:attr) }.to fail_with_message(message)
+ expect { expect(active_model_with(:attr)).to validate_absence_of(:attr) }.to fail_with_message(message)
end
end
context 'a has_many association with an absence validation' do
it 'requires the attribute to not be set' do
- having_many(:children, absence: true).should validate_absence_of(:children)
+ expect(having_many(:children, absence: true)).to validate_absence_of(:children)
end
end
context 'a has_many association without an absence validation' do
it 'does not require the attribute to not be set' do
- having_many(:children, absence: false).
- should_not validate_absence_of(:children)
+ expect(having_many(:children, absence: false)).
+ not_to validate_absence_of(:children)
end
end
context 'an absent has_and_belongs_to_many association' do
it 'accepts' do
model = having_and_belonging_to_many(:children, absence: true)
- model.should validate_absence_of(:children)
+ expect(model).to validate_absence_of(:children)
end
end
context 'a non-absent has_and_belongs_to_many association' do
it 'rejects' do
model = having_and_belonging_to_many(:children, absence: false)
- model.should_not validate_absence_of(:children)
+ expect(model).not_to validate_absence_of(:children)
end
end
@@ -76,7 +76,7 @@
"%{attribute} must be blank in a %{model}")
expect {
- validating_absence_of(:attr).should validate_absence_of(:attr)
+ expect(validating_absence_of(:attr)).to validate_absence_of(:attr)
}.to_not raise_exception
end
end
@@ -84,13 +84,13 @@
context "an attribute with a context-dependent validation" do
context "without the validation context" do
it "does not match" do
- validating_absence_of(:attr, on: :customisable).should_not validate_absence_of(:attr)
+ expect(validating_absence_of(:attr, on: :customisable)).not_to validate_absence_of(:attr)
end
end
context "with the validation context" do
it "matches" do
- validating_absence_of(:attr, on: :customisable).should validate_absence_of(:attr).on(:customisable)
+ expect(validating_absence_of(:attr, on: :customisable)).to validate_absence_of(:attr).on(:customisable)
end
end
end
View
14 spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
@@ -3,29 +3,29 @@
describe Shoulda::Matchers::ActiveModel::ValidateAcceptanceOfMatcher do
context 'a model with an acceptance validation' do
it 'accepts when the attributes match' do
- validating_acceptance.should matcher
+ expect(validating_acceptance).to matcher
end
it 'does not overwrite the default message with nil' do
- validating_acceptance.should matcher.with_message(nil)
+ expect(validating_acceptance).to matcher.with_message(nil)
end
end
context 'a model without an acceptance validation' do
it 'rejects' do
- define_model(:example, attr: :string).new.should_not matcher
+ expect(define_model(:example, attr: :string).new).not_to matcher
end
end
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/)
+ expect(validating_acceptance(message: 'custom')).
+ to matcher.with_message(/custom/)
end
it 'rejects when the message does not match' do
- validating_acceptance(message: 'custom').
- should_not matcher.with_message(/wrong/)
+ expect(validating_acceptance(message: 'custom')).
+ not_to matcher.with_message(/wrong/)
end
end
View
16 spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb
@@ -3,35 +3,35 @@
describe Shoulda::Matchers::ActiveModel::ValidateConfirmationOfMatcher do
context '#description' do
it 'states that the confirmation must match its base attribute' do
- matcher.description.should eq 'require attr_confirmation to match attr'
+ expect(matcher.description).to eq 'require attr_confirmation to match attr'
end
end
context 'a model with a confirmation validation' do
it 'accepts' do
- validating_confirmation.should matcher
+ expect(validating_confirmation).to matcher
end
it 'does not override the default message with a blank' do
- validating_confirmation.should matcher.with_message(nil)
+ expect(validating_confirmation).to matcher.with_message(nil)
end
end
context 'a model without a confirmation validation' do
it 'rejects' do
- define_model(:example, attr: :string).new.should_not matcher
+ expect(define_model(:example, attr: :string).new).not_to matcher
end
end
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/)
+ expect(validating_confirmation(message: 'custom')).
+ to matcher.with_message(/custom/)
end
it 'rejects when the messages do not match' do
- validating_confirmation(message: 'custom').
- should_not matcher.with_message(/wrong/)
+ expect(validating_confirmation(message: 'custom')).
+ not_to matcher.with_message(/wrong/)
end
end
View
44 spec/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb
@@ -3,23 +3,23 @@
describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher do
context '#description' do
it 'states that it allows only numeric values' do
- matcher.description.should eq 'only allow numeric values for attr'
+ expect(matcher.description).to eq 'only allow numeric values for attr'
end
end
context 'with a model with a numericality validation' do
it 'accepts