[rspec-users] Rails View spec testing for content in <head>

Kristian Mandrup kmandrup.github at gmail.com
Mon Aug 23 09:54:43 EDT 2010

I am trying to test methods I have added to ActionView::Base through a
Rails 3 plugin.
Basically, I have been trying to test it "outside of Rails" if
possible, that is, to only load the bare minimum functionality.

Here is my Rails view with a custom method #area added, which uses

class MyView < ActionView::Base
  attr_accessor :current_user

  def area(clazz, &block)
    content = with_output_buffer(&block)
    content_tag :div, content, :class => clazz

view = MyView.new

require 'erb'

x = 42
template = ERB.new <<-EOF
  The value of x is: <%= my_area %>

puts template.result(binding)

my_area = view.area :mine do

puts my_area
my_area.should match /hello/

=> <div class="mine"></div>

Yeah, it outputs the content_tag without 'hello' since it is output in
a separate buffer. Bot sure how I would get around this!?
And how to introduce this behavior into ERB?

I guess I should read up on basic rspec view testing instead of trying
to roll my own rspec framework for it!
How would I do this using rspe-rails for RSpec 2?



More information about the rspec-users mailing list