Brandon Olivares
2009-Apr-04 06:14 UTC
[rspec-users] Phlip''s be_html_with was RE: Problem with Custom matcher and Blocks
Hi, I just found a custom matcher created by Phlip at http://gist.github.com/76136 So I added that to my project, and it mostly works great for what I''m trying to do, and the syntax is pretty nice. But anytime I try to use select, I get an error. I wonder if it''s conflicting with another method somewhere else? So I wondered if there is a way to get around this, since I''d like to test that my select field is there. it "should have a subject dropdown box" do response.body.should be_html_with { form :id => ''contact'' do label ''Subject'' select :id => ''subject'' end } end # it "should have a subject dropdown box" Thanks, Brandon
Phlip
2009-Apr-04 12:40 UTC
[rspec-users] Phlip''s be_html_with was RE: Problem with Custom matcher and Blocks
Brandon Olivares wrote:> I just found a custom matcher created by Phlip at > http://gist.github.com/76136That''s just a sketch. The real deal is at... gem install nokogiri assert2 require ''assert2/xhtml'' Report if that works better. You might find its inside source code is a little nicer, too.> So I added that to my project, and it mostly works great for what I''m trying > to do, and the syntax is pretty nice. > > But anytime I try to use select, I get an error. I wonder if it''s > conflicting with another method somewhere else?http://groups.google.com/group/merb/browse_thread/thread/3588d3f75fa0e65c Use select!. That''s a missing feature in Nokogiri::HTML::Builder, and its author might fix it. Until then, Nokogiri and I use bangs for three reasons: convert a misunderstanding into innocent HTML convert potential HTML into a new keyword (:xpath!, without!) convert an element.class shortcut into an element.id!> So I wondered if there is a way to get around this, since I''d like to test > that my select field is there.it "should have a subject dropdown box" do response.body.should be_html_with { form.contact! do label ''Subject'' select! :id => ''subject'' end } end # it "should have a subject dropdown box" Notice two things, folks - Brandon started his assertion with a unique container object. That''s nearly the only way to get reasonable diagnostics. I gave up on trying to report the "closest match", and now I only report the "first extent of HTML that matches your first element". Also notice that all assertions should have a "diagostic message" facility - like the third argument to the lowly assert_equal(in, out, message = nil). But assert_xhtml does not have a message=nil yet. I''m too busy this weekend making it interpret Ajax, as a drop-in replacement for assert_rjs: assert_rjs :replace_html, :label_7 do input.Top_Ranking! :type => :checked, :value => :Y input.cross_sale_1, :type => :hidden, :value => 7 end You write the RJS you need to match (like assert_rjs classic uses), and then you add an assert_xhtml block, and it works on the Element.update() payload itself. http://groups.google.com/group/ruby-talk-google/msg/b94d83ad2d5e6536 -- Phlip http://www.zeroplayer.com/
Phlip
2009-Apr-04 13:10 UTC
[rspec-users] Phlip''s be_html_with was RE: Problem with Custom matcher and Blocks
Uh oh.> select! :id => ''subject''select!.subject! !
Brandon Olivares
2009-Apr-04 14:42 UTC
[rspec-users] Phlip''s be_html_with was RE: Problem with Custom matcher and Blocks
Phlip, Wow thank you very much. Sorry for the double post, I originally accidently sent my post from another email address. Anyway, that''ll be a lot better, and more refined than my previous syntax. Also I really like your RJS assertions. I''ll have to test that out when I get to using AJAX. Thanks, Brandon> -----Original Message----- > From: rspec-users-bounces at rubyforge.org [mailto:rspec-users- > bounces at rubyforge.org] On Behalf Of Phlip > Sent: Saturday, April 04, 2009 8:40 AM > To: rspec-users at rubyforge.org > Subject: Re: [rspec-users] Phlip''s be_html_with was RE: Problem with > Custom matcher and Blocks > > Brandon Olivares wrote: > > > I just found a custom matcher created by Phlip at > > http://gist.github.com/76136 > > That''s just a sketch. The real deal is at... > > gem install nokogiri assert2 > > require ''assert2/xhtml'' > > Report if that works better. You might find its inside source code is a > little > nicer, too. > > > So I added that to my project, and it mostly works great for what I''m > trying > > to do, and the syntax is pretty nice. > > > > But anytime I try to use select, I get an error. I wonder if it''s > > conflicting with another method somewhere else? > > http://groups.google.com/group/merb/browse_thread/thread/3588d3f75fa0e6 > 5c > > Use select!. That''s a missing feature in Nokogiri::HTML::Builder, and > its author > might fix it. Until then, Nokogiri and I use bangs for three reasons: > > convert a misunderstanding into innocent HTML > convert potential HTML into a new keyword (:xpath!, without!) > convert an element.class shortcut into an element.id! > > > So I wondered if there is a way to get around this, since I''d like to > test > > that my select field is there. > > it "should have a subject dropdown box" do > response.body.should be_html_with { > form.contact! do > label ''Subject'' > select! :id => ''subject'' > end > } > end # it "should have a subject dropdown box" > > Notice two things, folks - Brandon started his assertion with a unique > container > object. That''s nearly the only way to get reasonable diagnostics. I > gave up on > trying to report the "closest match", and now I only report the "first > extent of > HTML that matches your first element". > > Also notice that all assertions should have a "diagostic message" > facility - > like the third argument to the lowly assert_equal(in, out, message > nil). But > assert_xhtml does not have a message=nil yet. > > I''m too busy this weekend making it interpret Ajax, as a drop-in > replacement for > assert_rjs: > > assert_rjs :replace_html, :label_7 do > input.Top_Ranking! :type => :checked, :value => :Y > input.cross_sale_1, :type => :hidden, :value => 7 > end > > You write the RJS you need to match (like assert_rjs classic uses), and > then you > add an assert_xhtml block, and it works on the Element.update() payload > itself. > > http://groups.google.com/group/ruby-talk-google/msg/b94d83ad2d5e6536 > > -- > Phlip > http://www.zeroplayer.com/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Brandon Olivares
2009-Apr-04 15:13 UTC
[rspec-users] Phlip''s be_html_with was RE: Problem with Custom matcher and Blocks
Phlip, Well, now it''s not failing if there is an error. This passes: it "should have a subject dropdown box" do response.body.should be_html_with { form.contact! do label ''Subject'' select!.subject! end } end # it "should have a subject dropdown box" As it should, but the following passes as well, which should not: it "should have a name field" do response.body.should be_html_with { form.contact! do label ''Name'' input.name! end } end # it "should have a name field" There is most definitely not a name field, nor its associated label. Thanks, Brandon> -----Original Message----- > From: rspec-users-bounces at rubyforge.org [mailto:rspec-users- > bounces at rubyforge.org] On Behalf Of Phlip > Sent: Saturday, April 04, 2009 8:40 AM > To: rspec-users at rubyforge.org > Subject: Re: [rspec-users] Phlip''s be_html_with was RE: Problem with > Custom matcher and Blocks > > Brandon Olivares wrote: > > > I just found a custom matcher created by Phlip at > > http://gist.github.com/76136 > > That''s just a sketch. The real deal is at... > > gem install nokogiri assert2 > > require ''assert2/xhtml'' > > Report if that works better. You might find its inside source code is a > little > nicer, too. > > > So I added that to my project, and it mostly works great for what I''m > trying > > to do, and the syntax is pretty nice. > > > > But anytime I try to use select, I get an error. I wonder if it''s > > conflicting with another method somewhere else? > > http://groups.google.com/group/merb/browse_thread/thread/3588d3f75fa0e6 > 5c > > Use select!. That''s a missing feature in Nokogiri::HTML::Builder, and > its author > might fix it. Until then, Nokogiri and I use bangs for three reasons: > > convert a misunderstanding into innocent HTML > convert potential HTML into a new keyword (:xpath!, without!) > convert an element.class shortcut into an element.id! > > > So I wondered if there is a way to get around this, since I''d like to > test > > that my select field is there. > > it "should have a subject dropdown box" do > response.body.should be_html_with { > form.contact! do > label ''Subject'' > select! :id => ''subject'' > end > } > end # it "should have a subject dropdown box" > > Notice two things, folks - Brandon started his assertion with a unique > container > object. That''s nearly the only way to get reasonable diagnostics. I > gave up on > trying to report the "closest match", and now I only report the "first > extent of > HTML that matches your first element". > > Also notice that all assertions should have a "diagostic message" > facility - > like the third argument to the lowly assert_equal(in, out, message > nil). But > assert_xhtml does not have a message=nil yet. > > I''m too busy this weekend making it interpret Ajax, as a drop-in > replacement for > assert_rjs: > > assert_rjs :replace_html, :label_7 do > input.Top_Ranking! :type => :checked, :value => :Y > input.cross_sale_1, :type => :hidden, :value => 7 > end > > You write the RJS you need to match (like assert_rjs classic uses), and > then you > add an assert_xhtml block, and it works on the Element.update() payload > itself. > > http://groups.google.com/group/ruby-talk-google/msg/b94d83ad2d5e6536 > > -- > Phlip > http://www.zeroplayer.com/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Phlip
2009-Apr-04 17:46 UTC
[rspec-users] Phlip''s be_html_with was RE: Problem with Custom matcher and Blocks
Brandon Olivares wrote:> it "should have a name field" do > response.body.should be_html_with { > form.contact! do > label ''Name'' > input.name! > end > } > end # it "should have a name field" > > There is most definitely not a name field, nor its associated label.Can you try the assert_xhtml version? I think it will drop in with: Spec::Runner.configure do |c| c.include Test::Unit::Assertions end be_html_with{} is something of a nail-soup issue for me because we always only use test/unit at my day job... sorry! I will look at the issue this weekend - the @failure_message might not bubble up to the RSpec wrapper correctly...
Brandon Olivares
2009-Apr-04 20:07 UTC
[rspec-users] Phlip''s be_html_with was RE: Problem with Custom matcher and Blocks
Hi, Yes that''s great! That works perfectly. I''d appreciate it if you could let me know about the be_html_with issue when you can though, as I like the natural language better. Thank you very much. Brandon> -----Original Message----- > From: rspec-users-bounces at rubyforge.org [mailto:rspec-users- > bounces at rubyforge.org] On Behalf Of Phlip > Sent: Saturday, April 04, 2009 1:46 PM > To: rspec-users at rubyforge.org > Subject: Re: [rspec-users] Phlip''s be_html_with was RE: Problem with > Custom matcher and Blocks > > Brandon Olivares wrote: > > > it "should have a name field" do > > response.body.should be_html_with { > > form.contact! do > > label ''Name'' > > input.name! > > end > > } > > end # it "should have a name field" > > > > There is most definitely not a name field, nor its associated label. > > Can you try the assert_xhtml version? I think it will drop in with: > > Spec::Runner.configure do |c| > c.include Test::Unit::Assertions > end > > be_html_with{} is something of a nail-soup issue for me because we > always only > use test/unit at my day job... sorry! > > I will look at the issue this weekend - the @failure_message might not > bubble up > to the RSpec wrapper correctly... > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Phlip
2009-Apr-05 02:59 UTC
[rspec-users] Phlip''s be_html_with was RE: Problem with Custom matcher and Blocks
Brandon Olivares wrote:> Yes that''s great! That works perfectly. > > I''d appreciate it if you could let me know about the be_html_with issue when > you can though, as I like the natural language better.i dunno about "natural language", but I expect to fix the RSpec language this weekend. (-;
Phlip
2009-Apr-05 04:08 UTC
[rspec-users] Phlip''s be_html_with was RE: Problem with Custom matcher and Blocks
Brandon Olivares wrote:> I''d appreciate it if you could let me know about the be_html_with issue when > you can though, as I like the natural language better.Add this monkey patch below require ''assert2/xhtml'': class BeHtmlWith def matches?(stwing, &block) @block ||= block @scope.wrap_expectation self do @doc = Nokogiri::HTML(stwing) return run_all_xpaths(build_xpaths) end end end Now, I''m off to finish manual tests of the new assert_rjs, and to pop a new version...
Brandon Olivares
2009-Apr-05 08:29 UTC
[rspec-users] Phlip''s be_html_with was RE: Problem with Custom matcher and Blocks
Hi, Thank you very much. Is there any documentation of the rest of assert2? I found a web site I think (assuming it''s the same thing), but there wasn''t really documentation for assert_xhtml or assert_rjs. Brandon> -----Original Message----- > From: rspec-users-bounces at rubyforge.org [mailto:rspec-users- > bounces at rubyforge.org] On Behalf Of Phlip > Sent: Sunday, April 05, 2009 12:09 AM > To: rspec-users at rubyforge.org > Subject: Re: [rspec-users] Phlip''s be_html_with was RE: Problem with > Custom matcher and Blocks > > Brandon Olivares wrote: > > > I''d appreciate it if you could let me know about the be_html_with > issue when > > you can though, as I like the natural language better. > > Add this monkey patch below require ''assert2/xhtml'': > > class BeHtmlWith > def matches?(stwing, &block) > @block ||= block > @scope.wrap_expectation self do > @doc = Nokogiri::HTML(stwing) > return run_all_xpaths(build_xpaths) > end > end > end > > Now, I''m off to finish manual tests of the new assert_rjs, and to pop a > new > version... > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Phlip
2009-Apr-05 10:56 UTC
[rspec-users] Phlip''s be_html_with was RE: Problem with Custom matcher and Blocks
Brandon Olivares wrote:> Is there any documentation of the rest of assert2? I found a web site I > think (assuming it''s the same thing), but there wasn''t really documentation > for assert_xhtml or assert_rjs.assert_rjs is still in the oven, and assert_xhtml arrived too fast to get anything more than its README: http://assert2.rubyforge.org/svn/README I used to take a train to work - that''s why the assert{ 2.0 } documentation itself is so... florid...