Skip to content

Commit

Permalink
Convert to RSpec expect syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmire committed Jan 20, 2014
1 parent dfce983 commit 4e74ba8
Show file tree
Hide file tree
Showing 37 changed files with 702 additions and 696 deletions.
2 changes: 1 addition & 1 deletion lib/shoulda/matchers/action_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,23 +27,23 @@ 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

context 'a controller that renders a partial' do
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

context 'given a context with layouts' do
it 'accepts that layout in that context' do
set_in_context_layout('happy')

controller_without_layout.should render_with_layout('happy').in_context(self)
expect(controller_without_layout).to render_with_layout('happy').in_context(self)
end

def set_in_context_layout(layout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@
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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions spec/shoulda/matchers/action_controller/route_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,53 @@
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

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

Expand Down
12 changes: 6 additions & 6 deletions spec/shoulda/matchers/action_controller/route_params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 4e74ba8

Please sign in to comment.