Checks if the controller assigned the variables given by name. If you want to check that a variable is not being assigned, please do:
should_not_assign_to(:user)
If you want to assure that a variable is being assigned to nil, do instead:
should_assign_to(:user).with(nil)
should_assign_to :user, :with_kind_of => User
should_assign_to :user, :with => proc{ users(:first) }
should_assign_to(:user){ users(:first) }
it { should assign_to(:user) }
it { should assign_to(:user, :with => users(:first)) }
it { should assign_to(:user, :with_kind_of => User) }
# File lib/remarkable_rails/action_controller/matchers/assign_to_matcher.rb, line 88
88: def assign_to(*args, &block)
89: AssignToMatcher.new(*args, &block).spec(self)
90: end
Checks if the controller filters the given params.
should_filter_params :password
should_not_filter_params :username
it { should filter_params(:password) }
it { should_not filter_params(:username) }
# File lib/remarkable_rails/action_controller/matchers/filter_params_matcher.rb, line 34
34: def filter_params(*params, &block)
35: FilterParamsMatcher.new(*params, &block).spec(self)
36: end
Passes if the response redirects to the given url. The url can be a string, a hash or can be supplied as a block (see examples below).
should_redirect_to{ users_url }
should_redirect_to(:action => 'index')
should_not_redirect_to(:controller => 'users', :action => 'new')
it { should redirect_to(users_url).with(302) }
it { should redirect_to(:action => 'index') }
it { should_not redirect_to(:controller => 'users', :action => 'new') }
# File lib/remarkable_rails/action_controller/matchers/redirect_to_matcher.rb, line 113
113: def redirect_to(expected=nil, options={}, &block)
114: RedirectToMatcher.new(expected, options, &block).spec(self)
115: end
Passes if the specified template (view file) is rendered by the response. This file can be any view file, including a partial.
template can include the controller path. It can also include an optional extension, which you only need to use when there is ambiguity.
Note that partials must be spelled with the preceding underscore.
All other options in respond_with are also available.
should_render_template 'list' should_render_template 'same_controller/list' should_render_template 'other_controller/list'
# with extensions
should_render_template 'list.rjs' should_render_template 'list.haml' should_render_template 'same_controller/list.rjs' should_render_template 'other_controller/list.rjs'
# partials
should_render_template '_a_partial' should_render_template 'same_controller/_a_partial' should_render_template 'other_controller/_a_partial'
# with options
should_render_template 'list', :layout => 'users'
should_render_template 'list', :content_type => :xml
should_render_template 'list', :content_type => /xml/
should_render_template 'list', :content_type => Mime::XML
it { should render_template('list').layout('users') }
it { should render_template('list').content_type(:xml) }
it { should render_template('list').content_type(/xml/) }
it { should render_template('list').content_type(Mime::XML) }
Extensions check does not work in Rails 2.1.x.
# File lib/remarkable_rails/action_controller/matchers/render_template_matcher.rb, line 124
124: def render_template(*args, &block)
125: options = args.extract_options!
126: options.merge!(:template => args.first)
127: RenderTemplateMatcher.new(options, &block).spec(self)
128: end
This is just a shortcut for render_template :layout => layout. It‘s also used for Shoulda compatibility. Check render_template for more information.
# File lib/remarkable_rails/action_controller/matchers/render_template_matcher.rb, line 133
133: def render_with_layout(*args, &block)
134: options = args.extract_options!
135: options.merge!(:layout => args.first)
136: RenderTemplateMatcher.new(options, &block).spec(self)
137: end
This is just a shortcut for render_template :layout => nil. It‘s also used for Shoulda compatibility. Check render_template for more information.
# File lib/remarkable_rails/action_controller/matchers/render_template_matcher.rb, line 142
142: def render_without_layout(options={}, &block)
143: options.merge!(:layout => nil)
144: RenderTemplateMatcher.new(options, &block).spec(self)
145: end
Passes if the response has the given status. Status can be a Symbol lik :success, :missing, :redirect and :error. Can be also a Fixnum, Range o any other symbol which matches to any of Rails status codes.
should_respond_with :success
should_respond_with :error, :body => /System error/
should_respond_with 301, :content_type => Mime::XML
should_respond_with 300..399, :content_type => Mime::XML
it { should respond_with(:success) }
it { should respond_with(:error).body(/System error/) }
it { should respond_with(301).content_type(Mime::XML) }
it { should respond_with(300..399).content_type(Mime::XML) }
# File lib/remarkable_rails/action_controller/matchers/respond_with_matcher.rb, line 107
107: def respond_with(*args, &block)
108: options = args.extract_options!
109: options.merge!(:with => args.first)
110: RespondWithMatcher.new(options, &block).spec(self)
111: end
This is just a shortcut for respond_with :body => body. Check respond_with for more information.
# File lib/remarkable_rails/action_controller/matchers/respond_with_matcher.rb, line 116
116: def respond_with_body(*args, &block)
117: options = args.extract_options!
118: # Since body can be also given as block, only merge if any arguments was
119: # actually sent.
120: options.merge!(:body => args.first) unless args.empty?
121: RespondWithMatcher.new(options, &block).spec(self)
122: end
This is just a shortcut for respond_with :content_type => content_type. It‘s also used for Shoulda compatibility. Check respond_with for more information.
# File lib/remarkable_rails/action_controller/matchers/respond_with_matcher.rb, line 128
128: def respond_with_content_type(*args, &block)
129: options = args.extract_options!
130: options.merge!(:content_type => args.first)
131: RespondWithMatcher.new(options, &block).spec(self)
132: end
Assert route generation AND route recognition.
# autodetects the :controller should_route :get, '/posts', :action => :index # explicitly specify :controller should_route :post, '/posts', :controller => :posts, :action => :create # non-string parameter should_route :get, '/posts/1', :controller => :posts, :action => :show, :id => 1 # string-parameter should_route :put, '/posts/1', :controller => :posts, :action => :update, :id => "1" should_route :delete, '/posts/1', :controller => :posts, :action => :destroy, :id => 1 should_route :get, '/posts/new', :controller => :posts, :action => :new # nested routes should_route :get, '/users/5/posts', :controller => :posts, :action => :index, :user_id => 5 should_route :post, '/users/5/posts', :controller => :posts, :action => :create, :user_id => 5
# File lib/remarkable_rails/action_controller/matchers/route_matcher.rb, line 103
103: def route(*params, &block)
104: RouteMatcher.new(*params, &block).spec(self)
105: end
Ensures that the given cookie keys were set. If you want to check that a cookie is not being set, just do:
should_not_set_cookies :user
If you want to assure that a cookie is being set to nil, do instead:
should_set_cookies :user, :to => nil
Note: this method is also aliased as set_cookie.
should_set_cookies :user_id, :user
should_set_cookies :user_id, :to => 2
should_set_cookies :user, :to => proc{ users(:first) }
should_set_cookies(:user){ users(:first) }
it { should set_cookies(:user_id, :user) }
it { should set_cookies(:user_id, :to => 2) }
it { should set_cookies(:user, :to => users(:first)) }
# File lib/remarkable_rails/action_controller/matchers/set_cookies_matcher.rb, line 78
78: def set_cookies(*args, &block)
79: SetCookiesMatcher.new(*args, &block).spec(self)
80: end
Ensures that the given session keys were set. If you want to check that a variable is not being set, just do:
should_not_set_session :user
If you want to assure that a variable is being set to nil, do instead:
should_set_session :user, :to => nil
should_set_session :user_id, :user
should_set_session :user_id, :to => 2
should_set_session :user, :to => proc{ users(:first) }
should_set_session(:user){ users(:first) }
it { should set_session(:user_id, :user) }
it { should set_session(:user_id, :to => 2) }
it { should set_session(:user, :to => users(:first)) }
# File lib/remarkable_rails/action_controller/matchers/set_session_matcher.rb, line 102
102: def set_session(*args, &block)
103: SetSessionMatcher.new(*args, &block).spec(self)
104: end
Ensures that a flash message is being set. If you want to check that a flash is not being set, just do:
should_not_set_the_flash :user
If you want to assure that a flash is being set to nil, do instead:
should_set_the_flash :user, :to => nil
should_set_the_flash
should_not_set_the_flash
should_set_the_flash :to => 'message'
should_set_the_flash :notice, :warn
should_set_the_flash :notice, :to => 'message'
should_set_the_flash :notice, :to => proc{ 'hi ' + users(:first).name }
should_set_the_flash(:notice){ 'hi ' + users(:first).name }
it { should set_the_flash }
it { should set_the_flash.to('message') }
it { should set_the_flash(:notice, :warn) }
it { should set_the_flash(:notice, :to => 'message') }
it { should set_the_flash(:notice, :to => ('hi ' + users(:first).name)) }
# File lib/remarkable_rails/action_controller/matchers/set_the_flash_matcher.rb, line 50
50: def set_the_flash(*args, &block)
51: SetTheFlashMatcher.new(*args, &block).spec(self)
52: end