[rspec-devel] [ rspec-Bugs-7039 ] should_render_rjs :page, 'e', :replace_html, /t/ FAILS (tries to match incorrectly)

noreply at rubyforge.org noreply at rubyforge.org
Sun Jan 28 23:27:01 EST 2007


Bugs item #7039, was opened at 2006-12-04 13:04
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=7039&group_id=797

Category: rails plugin
Group: None
>Status: Closed
>Resolution: Out of Date
Priority: 3
Submitted By: Michael Johnston (lastobelus)
>Assigned to: David Chelimsky (dchelimsky)
Summary: should_render_rjs :page, 'e', :replace_html, /t/ FAILS (tries to match incorrectly)

Initial Comment:
given the following action:

  def stuff
    render :update { |page|  page[:bob].replace_html "sometext" }
  end 

the following spec:

  specify "should replace bob with 'sometext' on AJAX request to stuff" do
    get 'stuff'
    controller.should_render_rjs :page, 'bob', :replace_html, /some/
  end

Fails with the following report:

should replace bob with bob's string on AJAX request to stuff
"$(\bob\).update(\wtf!!!!!\);" should match /\$\("bob"\)\.update\(""\)\.\(\?\-mix:some\)\(\);/
/Users/lasto/clients/ibc/project_n/vendor/plugins/rspec/lib/spec/rails/rjs_expectations.rb:26:in `should_page'
/Users/lasto/clients/ibc/project_n/vendor/plugins/rspec/lib/spec/rails/rjs_expectations.rb:8:in `send'
/Users/lasto/clients/ibc/project_n/vendor/plugins/rspec/lib/spec/rails/rjs_expectations.rb:8:in `should_have_rjs'
/Users/lasto/clients/ibc/project_n/vendor/plugins/rspec/lib/extensions/action_controller/test_response.rb:6:in `should_have_rjs'
/Users/lasto/clients/ibc/project_n/vendor/plugins/rspec/lib/spec/rails/render_matcher.rb:58:in `should_render_rjs'
/Users/lasto/clients/ibc/project_n/vendor/plugins/rspec/lib/spec/rails/context/controller.rb:66:in `should_render_rjs'
./spec/controllers/ad_controller_spec.rb:84:

IE, the regex is simply being appended to the update call instead of matching inside the parameter to the update call.

I had a go at figuring it out, but it was beyond my ability to understand in the amount of time I had to spend on it. I think some extra parsing has to be done after the call to JavascriptGenerator? I don't know whether JavascriptGenerator is supposed to be able to stick a regex.to_s inside the update() call and the signature of the call to it is wrong, or if an empty "update" template needs to be retrieved from JavascriptGenerator and the regex inserted into it. 

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

>Comment By: David Chelimsky (dchelimsky)
Date: 2007-01-29 04:27

Message:
We're replacing should_have_rjs with should be_rjs, which wraps assert_select so you'll be to do everything you can do w/ assert_select.

This is already implemented in the trunk (rev 1440) so if you're using the trunk, look at the rdocs for Spec::Rails::Matchers (though the specific module may move to Spec::Expectations::Matchers before the release).

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

Comment By: David Chelimsky (dchelimsky)
Date: 2006-12-20 01:30

Message:
Actually, it looks like ARTS, from which should_have_rjs was ported, doesn't even support this. It only supports the following forms of page['id']:

page['some_id'].toggle

page['some_id'].style.color = 'red'

I'm working on an assert_select wrapper for rspec right now. If this ends up supporting spec'ing the forms you're looking for we probably won't go any farther on should_have_rjs.

I'll follow up as things evolve.

In the mean time, if you use this form in your app:

page.replace 'mydiv', 'replacement text'

you can spec it.

David

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

Comment By: David Chelimsky (dchelimsky)
Date: 2006-12-20 01:07

Message:
You're fine - we didn't have any specs using :page and :replace_.....

Working on it now. Sadly, just released 0.7.5, so it'll be a bit before the fix is released, but you can grab the trunk as soon as we get the fix in.

David

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

Comment By: Michael Johnston (lastobelus)
Date: 2006-12-19 23:38

Message:
Hi David,

Any feedback on this? If I'm doing something stupid I would really appreciate 
finding out what it is.

As it stands, the should_render_rjs seems simply not to work. I tried it with 
non-edge rails and got the same result.

BTW, I did notice I put the wrong div name in the second spec (changed now 
in the linked archive) HOWEVER this has no effect on the result as the error is 
unrelated to that.

Can we re-open the bug? Maybe somebody else has an answer.

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

Comment By: Michael Johnston (lastobelus)
Date: 2006-12-05 17:11

Message:
I created a brand new edge rails app, using the following procedure:

  281  rails rjstest
  282  cd rjstest/
  283  rake rails:freeze:edge
  284  script/plugin install svn://rubyforge.org/var/svn/rspec/tags/
REL_0_7_4/vendor/rspec_on_rails/vendor/plugins/rspec
  289  ruby script/generate rspec_controller bob
  290  mate .
  292  ruby script/generate rspec
  295  spec spec/controllers/bob_controller_spec.rb 

Both problems are demonstrated.

Here is a link to an archive of it:

http://www.lastmetal.com/misc/rjstest.tgz



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

Comment By: David Chelimsky (dchelimsky)
Date: 2006-12-05 16:24

Message:
Would you mind posting your the spec and controller code?

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

Comment By: Michael Johnston (lastobelus)
Date: 2006-12-05 16:18

Message:
Ok, I certainly tried it that way. However in my setup ALL the 
should_render_rjs  forms report: 

1)
NoMethodError in 'The HomeController should replace bob with 'sometext' on 
AJAX request to stuff'
nil does not respond to `rjs' or `has_rjs?'

when the should_render_rjs is called before the GET. I posted about this a few 
days ago on the mailing list, but haven't found an answer as to why. I am 
using edge rails, and to my knowledge there is nothing extra or unusual in 
my setup

And, I discovered, the other forms of should_render_rjs do work correctly 
with the call after the request. I believe the two issues are orthogonal.

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

Comment By: David Chelimsky (dchelimsky)
Date: 2006-12-05 16:01

Message:
http://rspec.rubyforge.org/documentation/rails/writing/controllers.html

You have to put the controller.should_render_rjs call BEFORE the get:

specify "should replace bob with 'sometext' on AJAX request to stuff" do
    controller.should_render_rjs :page, 'bob', :replace_html, /some/
    get 'stuff'
  end

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

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


More information about the rspec-devel mailing list