Ashley Moran
2007-Jun-15 09:53 UTC
[rspec-users] Is it still possible to use should_have_rjs
Hi I''ve come back to a Rails project after about a month doing other work, and there''s a lot of changes. I was on the 0.7 branch before and I''ve upgraded to RSpec 1.0.5. I used the spec translator, fixed the cases where it barfed on unusual line contents, and all my model and controller specs now pass. But I''m getting 53 failures on my view specs, all along the lines of: should have visual effect Unknown RJS statement type effect /Users/ashleymoran/Documents/Development/YourMoney/trunk/src/spec/ views/admin/add_dealer_rjs_view_spec.rb:33 31 32 it "should have visual effect" do 33 response.should have_rjs(:effect, :blind_down, "add_dealer") 34 end 35 I''m trying to revert these to should_have_rjs but I''ve looked through the RSpec source and it seems should_have_rjs was silently removed between 0.8 and 0.9. At least I can''t find any reference to it in the 0.9.4 source or the 1.0.5 source. Am I missing something? I really need should_have_rjs- those 53 failures represent about 20% of all my view specs. Thanks Ashley
David Chelimsky
2007-Jun-15 11:42 UTC
[rspec-users] Is it still possible to use should_have_rjs
On 6/15/07, Ashley Moran <work at ashleymoran.me.uk> wrote:> Hi > > I''ve come back to a Rails project after about a month doing other > work, and there''s a lot of changes. I was on the 0.7 branch before > and I''ve upgraded to RSpec 1.0.5. I used the spec translator, fixed > the cases where it barfed on unusual line contents, and all my model > and controller specs now pass. But I''m getting 53 failures on my view > specs, all along the lines of: > > should have visual effect > Unknown RJS statement type effect > /Users/ashleymoran/Documents/Development/YourMoney/trunk/src/spec/ > views/admin/add_dealer_rjs_view_spec.rb:33 > 31 > 32 it "should have visual effect" do > 33 response.should have_rjs(:effect, :blind_down, "add_dealer") > 34 end > 35 > > I''m trying to revert these to should_have_rjs but I''ve looked through > the RSpec source and it seems should_have_rjs was silently removed > between 0.8 and 0.9. At least I can''t find any reference to it in > the 0.9.4 source or the 1.0.5 source. Am I missing something?You''re not missing anything. I switched from a direct port of ARTS to wrapping assert_select_rjs in 0.9. Neither library covers the full breadth of rjs statements and I went w/ the wrapper because it meant that rspec would reap the benefits of improvements to assert_select_rjs. Sadly, it seems as though the only improvements to assert_select_rjs have been those that I''ve personally contributed to Rails, and they haven''t covered every situation. As for your immediate problem, Spec::Rails provides access to Test::Unit assertions for free. I''d recommend that you install the ARTS plugin (from which should_have_rjs was ported) and use it directly as/is (assert_rjs) right in your examples. It won''t be as pleasing syntactically, but at least it should work for you. http://glu.ttono.us/articles/2006/05/29/guide-test-driven-rjs-with-arts There are a couple of things that ARTS didn''t cover that we had added to RSpec. Those you''ll have to do manually with any of these: response.should have_text("full text of the response") response.should have_text(/regexp representing a substring of the response/) response.body.should == "full text of the response" response.body.should =~ /regexp representing a substring of the response/ In terms of a longer term solution for rspec, I''m open to suggestions. ARTS and assert_select_rjs both make assumptions about what options are available, which means they both need to be updated as new options appear. I had hoped that this would be maintained in rails, but it doesn''t appear to be happening. We could resurrect ARTS in RSpec, but that would mean either coming up with a new matcher (include_rjs?) as not to break existing specs that use "should have_rjs.", and it would put more of a burden on Spec::Rails to keep up with additions to rjs. Other ideas? David> I > really need should_have_rjs- those 53 failures represent about 20% of > all my view specs. > > Thanks > Ashley > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Ashley Moran
2007-Jun-15 15:55 UTC
[rspec-users] Is it still possible to use should_have_rjs
On 15 Jun 2007, at 12:42, David Chelimsky wrote:> You''re not missing anything. I switched from a direct port of ARTS to > wrapping assert_select_rjs in 0.9. Neither library covers the full > breadth of rjs statements and I went w/ the wrapper because it meant > that rspec would reap the benefits of improvements to > assert_select_rjs. Sadly, it seems as though the only improvements to > assert_select_rjs have been those that I''ve personally contributed to > Rails, and they haven''t covered every situation.Hmm, surely RJS testing is a pretty essential part of Rails, seeing how everyone''s going Web2.0-crazy? I''m surprised assert_select_rjs doesn''t cover everything.> As for your immediate problem, Spec::Rails provides access to > Test::Unit assertions for free. I''d recommend that you install the > ARTS plugin (from which should_have_rjs was ported) and use it > directly as/is (assert_rjs) right in your examples. It won''t be as > pleasing syntactically, but at least it should work for you. > > http://glu.ttono.us/articles/2006/05/29/guide-test-driven-rjs-with- > artsThanks for the link. I tried this: describe "A rendered add_dealer view" do before(:each) do render ''admin/add_dealer'' end it "should have visual effect" do assert_rjs(:effect, :blind_down, "add_dealer") end end But it doesn''t work: should have visual effect ActionView::Helpers::JavaScriptProxy#to_str should return String /Users/ashleymoran/Documents/Development/YourMoney/trunk/src/ config/../vendor/plugins/arts/lib/arts.rb:98 :in `index'' /Users/ashleymoran/Documents/Development/YourMoney/trunk/src/ config/../vendor/plugins/arts/lib/arts.rb:98 :in `assert_response_contains'' /Users/ashleymoran/Documents/Development/YourMoney/trunk/src/ config/../vendor/plugins/arts/lib/arts.rb:12 :in `assert_rjs'' ./spec/views/admin/add_dealer_rjs_view_spec.rb:33 96 97 def assert_response_contains(str, message) 98 assert @response.body.to_s.index(str), message 99 end 100 My naive attempt to fix it... module ActionView module Helpers class JavaScriptProxy def to_str to_s end end end end achieves nothing. (Probably because it''s completely wrong.) Any ideas on this one?> There are a couple of things that ARTS didn''t cover that we had added > to RSpec. Those you''ll have to do manually with any of these: > > response.should have_text("full text of the response") > response.should have_text(/regexp representing a substring of the > response/) > response.body.should == "full text of the response" > response.body.should =~ /regexp representing a substring of the > response/ > > In terms of a longer term solution for rspec, I''m open to suggestions. > ARTS and assert_select_rjs both make assumptions about what options > are available, which means they both need to be updated as new options > appear. I had hoped that this would be maintained in rails, but it > doesn''t appear to be happening.Hmm, surely a framework feature without a means to test it is next to useless? Or maybe I am being a too demanding (I''m known for it).> We could resurrect ARTS in RSpec, but that would mean either coming up > with a new matcher (include_rjs?) as not to break existing specs that > use "should have_rjs.", and it would put more of a burden on > Spec::Rails to keep up with additions to rjs.Is there any way to be clever with have_rjs and decide where to pass the request based on the type of match? That way you could use ARTS as a prop and migrate test support to assert_select_rjs as and when things as included? I haven''t written any custom matchers yet - don''t know much about the new style specs thanks to lack of time spent coding - so again I''m probably being naive. Ashley