class Spec::Rails::Example::ViewExampleGroup
end<br>end<br>end<br>with_tag(“input[value=Login]”)<br>with_tag(“input[name=password]”)<br>with_tag(“input[name=email]”)
response.should have_tag(“form”) do
it “should display login form” do
end
render ‘login/login’
before do
describe “login/login” do
== Example
expectations that you can set on views.
See Spec::Rails::Expectations::Matchers for information about specific
which provides access to views without invoking any of your controllers.
View Specs use Spec::Rails::Example::ViewExampleGroup,
View Examples live in $RAILS_ROOT/spec/views/.
def _assigns_hash_proxy
def _assigns_hash_proxy @_assigns_hash_proxy ||= AssignsHashProxy.new(self) {@response.template} end
def add_helpers(options) #:nodoc:
def add_helpers(options) #:nodoc: @controller.add_helper("application") @controller.add_helper(derived_controller_name(options)) @controller.add_helper(options[:helper]) if options[:helper] options[:helpers].each { |helper| @controller.add_helper(helper) } if options[:helpers] end
def base_view_path(options) #:nodoc:
def base_view_path(options) #:nodoc: "/#{derived_controller_name(options)}/" end
def derived_action_name(options) #:nodoc:
def derived_action_name(options) #:nodoc: parts = subject_of_render(options).split('/').reject { |part| part.empty? } "#{parts.last}".split('.').first end
def derived_controller_name(options) #:nodoc:
def derived_controller_name(options) #:nodoc: parts = subject_of_render(options).split('/').reject { |part| part.empty? } "#{parts[0..-2].join('/')}" end
def ensure_that_base_view_path_is_not_set_across_example_groups #:nodoc:
def ensure_that_base_view_path_is_not_set_across_example_groups #:nodoc: ActionView::Base.base_view_path = nil end
def ensure_that_flash_and_session_work_properly #:nodoc:
def ensure_that_flash_and_session_work_properly #:nodoc: @controller.class.__send__ :public, :flash @controller.__send__ :initialize_template_class, @response @controller.__send__ :assign_shortcuts, @request, @response @controller.__send__ :initialize_current_url @session = @controller.session end
def inherited(klass) # :nodoc:
def inherited(klass) # :nodoc: klass.subject { template } super end
def render(*args)
render(:inline => "<% custom_helper 'argument', 'another argument' %>")
render(:partial => '/people/_address')
render('/people/list', :helpers => [MyHelper, MyOtherHelper])
render('/people/list', :helper => MyHelper)
render('/people/list')
== Examples
use to spec custom form builders, helpers, etc, in the context of a view.
through the +response+. Also supports render with :inline, which you can
Renders a template for a View Spec, which then provides access to the result
def render(*args) options = Hash === args.last ? args.pop : {} if args.empty? unless [:partial, :inline, :file, :template, :xml, :json, :update].any? {|k| options.has_key? k} args << self.class.description_parts.first end end options[:template] = args.first.to_s.sub(/^\//,'') unless args.empty? set_base_view_path(options) add_helpers(options) assigns[:action_name] = @action_name @request.path_parameters = @request.path_parameters.merge( :controller => derived_controller_name(options), :action => derived_action_name(options) ).merge(options[:path_parameters] || {}) defaults = { :layout => false } options = defaults.merge options @controller.__send__(:params).reverse_merge! @request.parameters @controller.class.instance_eval %{ def controller_path "#{derived_controller_name(options)}" end def controller_name "#{derived_controller_name(options).split('/').last}" end } @controller.__send__ :forget_variables_added_to_assigns @controller.__send__ :render, options @controller.__send__ :process_cleanup end
def set_base_view_path(options) #:nodoc:
def set_base_view_path(options) #:nodoc: ActionView::Base.base_view_path = base_view_path(options) end
def subject_of_render(options) #:nodoc:
def subject_of_render(options) #:nodoc: [:template, :partial, :file].each do |render_type| if options.has_key?(render_type) return options[render_type] end end return "" end
def template
end
render "/person/new"
template.should_receive(:render).with(:partial => 'form')
it "should use the form partial" do
describe "/person/new" do
== Example
expectations for dealing with partials
This provides the template. Use this to set mock
def template @controller.template end