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
#with_output_buffer
class MyView < ActionView::Base
attr_accessor :current_user
def area(clazz, &block)
content = with_output_buffer(&block)
content_tag :div, content, :class => clazz
end
end
view = MyView.new
require 'erb'
x = 42
template = ERB.new <<-EOF
The value of x is: <%= my_area %>
EOF
puts template.result(binding)
my_area = view.area :mine do
'hello'
end
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?
Thanks!
Kristian
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users