[rspec-devel] [ rspec-Feature Requests-13616 ] [CODE included] Testing RJS helper methods

noreply at rubyforge.org noreply at rubyforge.org
Mon Nov 19 00:26:11 EST 2007


Feature Requests item #13616, was opened at 2007-09-03 07:23
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=13616&group_id=797

Category: None
Group: None
Status: Open
Priority: 3
Submitted By: Simon Nicholls (simon_nicholls)
Assigned to: Nobody (None)
Summary: [CODE included] Testing RJS helper methods

Initial Comment:
Hi,

I like to test my RJS helper methods using RSpec. These are the helper methods that have a page object implicitly provided for their use.

As an example, for:

update_page {|page| page.notify("kitten")} in the controller

With the helper being:

def notify(message)
  page[:notice].replace_html message
end

I can do:

describe AjaxHelper, "notify" do
  it "should update notice area" do
    rjs_for.notify("kitten").should have_rjs(:chained_replace_html, "notice")
  end
end

To do this, I include a Helper module, but it could be in core using code similar to the following (all in dsl/behaviour/helper.rb).

In ExampleMethods module, alongside eval_erb:

def rjs_for
  HelperRJSPageProxy.new(self)
end

Then where other classes are defined (e.g. HelperEvalContextController):

class HelperRJSPageProxy
  def initialize(context)
    @context = context
  end

  def method_missing(method, *arguments)
    block = Proc.new { |page|  @lines = []; page.send(method, *arguments) }
    @context.response.body = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(@context, &block).to_s
    @context.response
  end
end

I checked out the RSpec trunk, thinking to make a patch, but failed to get far with understanding RSpec's own spec layout and speccing the spec.

Hope you find the code useful! It's been handy to be able to test RJS helpers, and it would be great to have in core.

----------------------------------------------------------------------

Comment By: Chad Humphries (spicycode)
Date: 2007-11-19 00:26

Message:
Moved to http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/115-13616-code-included-testing-rjs-helper-methods

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=13616&group_id=797


More information about the rspec-devel mailing list