Kyle Hargraves
2008-Mar-26 19:08 UTC
[rspec-users] [ANN] rspec_hpricot_matchers 1.0: have_tag on hpricot
Hello everyone, A few weeks ago, I put together a little project that provides a have_tag() matcher look-alike that can be used outside of Rails projects, backed by Hpricot, which I very creatively named rspec_hpricot_matchers. It''s not a drop-in replacement for rspec_on_rails'' have_tag(): no substitution values, Hpricot''s CSS selectors aren''t identical to assert_select''s, and with_tag() has been replaced by nested calls to have_tag(). But it''s pretty close and even enjoys a few benefits over the standard implementation. I finally got around to registering a project on RubyForge and pushing a gem, so it is now available with just: gem install rspec_hpricot_matchers If you''re interested, the source is hosted on github at: github.com/pd/rspec_hpricot_matchers I''m using this both in isolated XML-related libraries and in my Rails projects, and I haven''t come up with any features I want lately, so it''s reasonably stable in my experience. Usage examples are available in the README, and the specs are simple enough to be another good set of examples. Suggestions, patches and angry flames about list spamming are all welcome. Thanks Kyle
Hi all! I''ve been through the RSpec Stories PeepCode and some various other readings online, and now I''m trying to build a dummy application of the traditional style: log in, make posts, add comments. So I''ve run the scaffold for posts/comments and the script for RestfulAuthentication so I have the users and SessionController and all that set up in this project. Now I''ve written this story: pastie.caboo.se/pastes/171140 In it I''m trying to do a post to "/session/create" in order to log in. I figure I want to be able to call this from an Story so that I can reuse it for different scenarios when I want to test things requiring login. What am I doing wrong here? Thanks! Glenn
On Mar 26, 2008, at 4:02 PM, Glenn Ford wrote:> Hi all! I''ve been through the RSpec Stories PeepCode and some various > other readings online, and now I''m trying to build a dummy application > of the traditional style: log in, make posts, add comments. > > So I''ve run the scaffold for posts/comments and the script for > RestfulAuthentication so I have the users and SessionController and > all that set up in this project. Now I''ve written this story: > > pastie.caboo.se/pastes/171140 > > In it I''m trying to do a post to "/session/create" in order to log > in. I figure I want to be able to call this from an Story so that I > can reuse it for different scenarios when I want to test things > requiring login. > > What am I doing wrong here?Glenn, please include a pastie that shows the error you are getting or the behavior that isn''t working. cr
Ashley Moran
2008-Mar-26 23:50 UTC
[rspec-users] [ANN] rspec_hpricot_matchers 1.0: have_tag on hpricot
On 26 Mar 2008, at 19:08, Kyle Hargraves wrote:> I finally got around to registering a project on RubyForge and pushing > a gem, so it is now available with just: > > gem install rspec_hpricot_matchersHi Kyle Thanks for releasing this as a gem, makes it much easier to get hold of. The only deficiency in it that bugs me is the poor error reporting for nested specs, but that would be pretty tough to fix. (I''d love to think I could add that but not sure I will get time.) I still think this should be in RSpec core though, hint hint David ;o) Is there any chance it will make it in? Making assertions about XML data is pretty common doing both web-based and non-web-based apps. Plus of course there is the little issue that Rails'' assert_select doesn''t *actually work*, which is generally considered a requirement for a testing library. Ashley
On Mar 26, 2008, at 6:28 PM, Chuck Remes wrote:> > On Mar 26, 2008, at 4:02 PM, Glenn Ford wrote: >> Hi all! I''ve been through the RSpec Stories PeepCode and some >> various >> other readings online, and now I''m trying to build a dummy >> application >> of the traditional style: log in, make posts, add comments. >> >> So I''ve run the scaffold for posts/comments and the script for >> RestfulAuthentication so I have the users and SessionController and >> all that set up in this project. Now I''ve written this story: >> >> pastie.caboo.se/pastes/171140 >> >> In it I''m trying to do a post to "/session/create" in order to log >> in. I figure I want to be able to call this from an Story so that I >> can reuse it for different scenarios when I want to test things >> requiring login. >> >> What am I doing wrong here? > > Glenn, > > please include a pastie that shows the error you are getting or the > behavior that isn''t working. > > crOh sorry about that... it was there before I promise :) FAILURES: 1) User Stuff (Create a new user) FAILED Spec::Expectations::ExpectationNotMetError: expected redirect? to return true, got false stories/user_story.rb:34:in `I should be logged in'' stories/user_story.rb:31 stories/user_story.rb:3
Hi Glen, I do not mean to insult you, but is /session/create actually doing a redirect? A similar rspec test works for me. -- Matt Berther mattberther.com On Mar 26, 2008, at 5:51 PM, Glenn Ford wrote:> On Mar 26, 2008, at 6:28 PM, Chuck Remes wrote: > >> >> On Mar 26, 2008, at 4:02 PM, Glenn Ford wrote: >>> Hi all! I''ve been through the RSpec Stories PeepCode and some >>> various >>> other readings online, and now I''m trying to build a dummy >>> application >>> of the traditional style: log in, make posts, add comments. >>> >>> So I''ve run the scaffold for posts/comments and the script for >>> RestfulAuthentication so I have the users and SessionController and >>> all that set up in this project. Now I''ve written this story: >>> >>> pastie.caboo.se/pastes/171140 >>> >>> In it I''m trying to do a post to "/session/create" in order to log >>> in. I figure I want to be able to call this from an Story so that I >>> can reuse it for different scenarios when I want to test things >>> requiring login. >>> >>> What am I doing wrong here? >> >> Glenn, >> >> please include a pastie that shows the error you are getting or the >> behavior that isn''t working. >> >> cr > > Oh sorry about that... it was there before I promise :) > > FAILURES: > 1) User Stuff (Create a new user) FAILED > Spec::Expectations::ExpectationNotMetError: expected redirect? to > return true, got false > stories/user_story.rb:34:in `I should be logged in'' > stories/user_story.rb:31 > stories/user_story.rb:3 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > rubyforge.org/mailman/listinfo/rspec-users
It actually should do a redirect, but checking for response.should be_success also fails. The request isn''t actually being made. I just can''t figure out why. Glenn On Mar 26, 2008, at 8:19 PM, Matt Berther wrote:> Hi Glen, > > I do not mean to insult you, but is /session/create actually doing a > redirect? A similar rspec test works for me. > > -- > Matt Berther > mattberther.com > > > > > On Mar 26, 2008, at 5:51 PM, Glenn Ford wrote: > >> On Mar 26, 2008, at 6:28 PM, Chuck Remes wrote: >> >>> >>> On Mar 26, 2008, at 4:02 PM, Glenn Ford wrote: >>>> Hi all! I''ve been through the RSpec Stories PeepCode and some >>>> various >>>> other readings online, and now I''m trying to build a dummy >>>> application >>>> of the traditional style: log in, make posts, add comments. >>>> >>>> So I''ve run the scaffold for posts/comments and the script for >>>> RestfulAuthentication so I have the users and SessionController and >>>> all that set up in this project. Now I''ve written this story: >>>> >>>> pastie.caboo.se/pastes/171140 >>>> >>>> In it I''m trying to do a post to "/session/create" in order to log >>>> in. I figure I want to be able to call this from an Story so >>>> that I >>>> can reuse it for different scenarios when I want to test things >>>> requiring login. >>>> >>>> What am I doing wrong here? >>> >>> Glenn, >>> >>> please include a pastie that shows the error you are getting or the >>> behavior that isn''t working. >>> >>> cr >> >> Oh sorry about that... it was there before I promise :) >> >> FAILURES: >> 1) User Stuff (Create a new user) FAILED >> Spec::Expectations::ExpectationNotMetError: expected redirect? to >> return true, got false >> stories/user_story.rb:34:in `I should be logged in'' >> stories/user_story.rb:31 >> stories/user_story.rb:3 >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > rubyforge.org/mailman/listinfo/rspec-users
David Chelimsky
2008-Mar-27 02:13 UTC
[rspec-users] [ANN] rspec_hpricot_matchers 1.0: have_tag on hpricot
On Wed, Mar 26, 2008 at 7:50 PM, Ashley Moran <ashley.moran at patchspace.co.uk> wrote:> > On 26 Mar 2008, at 19:08, Kyle Hargraves wrote: > > > I finally got around to registering a project on RubyForge and pushing > > a gem, so it is now available with just: > > > > gem install rspec_hpricot_matchers > > > Hi Kyle > > Thanks for releasing this as a gem, makes it much easier to get hold > of. The only deficiency in it that bugs me is the poor error > reporting for nested specs, but that would be pretty tough to fix. > (I''d love to think I could add that but not sure I will get time.) > > I still think this should be in RSpec core though, hint hint > David ;o) Is there any chance it will make it in?Not likely. Not because it isn''t awesome. I''ll probably be using it myself. But every good idea for a matcher library doesn''t belong in rspec. In fact, the whole point of creating such a simple protocol for matchers was to encourage external libraries. I think it''s fine just as it is. FWIW, David> Making assertions > about XML data is pretty common doing both web-based and non-web-based > apps. Plus of course there is the little issue that Rails'' > assert_select doesn''t *actually work*, which is generally considered a > requirement for a testing library.> > Ashley > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > rubyforge.org/mailman/listinfo/rspec-users >
On Wed, Mar 26, 2008 at 5:02 PM, Glenn Ford <glenn at aldenta.com> wrote:> Hi all! I''ve been through the RSpec Stories PeepCode and some various > other readings online, and now I''m trying to build a dummy application > of the traditional style: log in, make posts, add comments. > > So I''ve run the scaffold for posts/comments and the script for > RestfulAuthentication so I have the users and SessionController and > all that set up in this project. Now I''ve written this story: > > pastie.caboo.se/pastes/171140Shouldn''t that be a post to "/sessons/"?> > In it I''m trying to do a post to "/session/create" in order to log > in. I figure I want to be able to call this from an Story so that I > can reuse it for different scenarios when I want to test things > requiring login. > > What am I doing wrong here? > > Thanks! > Glenn > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > rubyforge.org/mailman/listinfo/rspec-users >
That was it, thank you! Must have been a long day, I can''t believe I didn''t spot that :) On Mar 26, 2008, at 10:15 PM, David Chelimsky wrote:> On Wed, Mar 26, 2008 at 5:02 PM, Glenn Ford <glenn at aldenta.com> wrote: >> Hi all! I''ve been through the RSpec Stories PeepCode and some >> various >> other readings online, and now I''m trying to build a dummy >> application >> of the traditional style: log in, make posts, add comments. >> >> So I''ve run the scaffold for posts/comments and the script for >> RestfulAuthentication so I have the users and SessionController and >> all that set up in this project. Now I''ve written this story: >> >> pastie.caboo.se/pastes/171140 > > Shouldn''t that be a post to "/sessons/"? > >> >> In it I''m trying to do a post to "/session/create" in order to log >> in. I figure I want to be able to call this from an Story so that I >> can reuse it for different scenarios when I want to test things >> requiring login. >> >> What am I doing wrong here? >> >> Thanks! >> Glenn >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > rubyforge.org/mailman/listinfo/rspec-users
Ashley Moran
2008-Mar-27 16:27 UTC
[rspec-users] [ANN] rspec_hpricot_matchers 1.0: have_tag on hpricot
On 27/03/2008, David Chelimsky <dchelimsky at gmail.com> wrote:> > Not likely. Not because it isn''t awesome. I''ll probably be using it > myself. But every good idea for a matcher library doesn''t belong in > rspec. In fact, the whole point of creating such a simple protocol for > matchers was to encourage external libraries. > > I think it''s fine just as it is.In that case, would a central repository of re-usable matchers be a good idea? (Maybe just a page on rspec.info?) Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: rubyforge.org/pipermail/rspec-users/attachments/20080327/503b8bb9/attachment.html
Corey Haines
2008-Mar-27 16:49 UTC
[rspec-users] [ANN] rspec_hpricot_matchers 1.0: have_tag on hpricot
+1 On Thu, Mar 27, 2008 at 12:27 PM, Ashley Moran < ashley.moran at patchspace.co.uk> wrote:> On 27/03/2008, David Chelimsky <dchelimsky at gmail.com> wrote: > > > Not likely. Not because it isn''t awesome. I''ll probably be using it > > myself. But every good idea for a matcher library doesn''t belong in > > rspec. In fact, the whole point of creating such a simple protocol for > > matchers was to encourage external libraries. > > > > I think it''s fine just as it is. > > > > In that case, would a central repository of re-usable matchers be a good > idea? (Maybe just a page on rspec.info?) > > > Ashley > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > rubyforge.org/mailman/listinfo/rspec-users >-- coreyhaines.com The Internet''s Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: rubyforge.org/pipermail/rspec-users/attachments/20080327/b7685dfb/attachment.html
Jonathan Leighton
2008-Mar-27 18:18 UTC
[rspec-users] [ANN] rspec_hpricot_matchers 1.0: have_tag on hpricot
+2.74 On Thu, 2008-03-27 at 12:49 -0400, Corey Haines wrote:> +1 > > On Thu, Mar 27, 2008 at 12:27 PM, Ashley Moran > <ashley.moran at patchspace.co.uk> wrote: > On 27/03/2008, David Chelimsky <dchelimsky at gmail.com> wrote: > Not likely. Not because it isn''t awesome. I''ll > probably be using it > myself. But every good idea for a matcher library > doesn''t belong in > rspec. In fact, the whole point of creating such a > simple protocol for > matchers was to encourage external libraries. > > I think it''s fine just as it is. > > > In that case, would a central repository of re-usable matchers > be a good idea? (Maybe just a page on rspec.info?) > > > Ashley > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > rubyforge.org/mailman/listinfo/rspec-users > > > > -- > coreyhaines.com > The Internet''s Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > rubyforge.org/mailman/listinfo/rspec-users-- Jonathan Leighton jonathanleighton.com
David Chelimsky
2008-Mar-27 19:24 UTC
[rspec-users] [ANN] rspec_hpricot_matchers 1.0: have_tag on hpricot
On Mar 27, 2008, at 12:27 PM, "Ashley Moran" <ashley.moran at patchspace.co.uk > wrote:> On 27/03/2008, David Chelimsky <dchelimsky at gmail.com> wrote: > Not likely. Not because it isn''t awesome. I''ll probably be using it > myself. But every good idea for a matcher library doesn''t belong in > rspec. In fact, the whole point of creating such a simple protocol for > matchers was to encourage external libraries. > > I think it''s fine just as it is. > > > In that case, would a central repository of re-usable matchers be a > good idea? (Maybe just a page on rspec.info?)Definitely. We''re going to set up a wiki or some such. I''m interested in a place to list matcher libs, plugins, and projects that are using rspec as well. Soon! Maybe ;) Cheers, David> > > > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > rubyforge.org/mailman/listinfo/rspec-users-------------- next part -------------- An HTML attachment was scrubbed... URL: rubyforge.org/pipermail/rspec-users/attachments/20080327/5d01e561/attachment.html
Corey Haines
2008-Apr-02 14:18 UTC
[rspec-users] [ANN] rspec_hpricot_matchers 1.0: have_tag on hpricot
Just thought I''d send out a little update on using this library. Great! We converted our tests over to using it, and I''m very happy with it. Good job, Kyle! Keep up the good work. It did take a bit of time to convert (using @ in attributes, for example), but it was well worth it. -Corey On Wed, Mar 26, 2008 at 3:08 PM, Kyle Hargraves <philodespotos at gmail.com> wrote:> Hello everyone, > > A few weeks ago, I put together a little project that provides a > have_tag() matcher look-alike that can be used outside of Rails > projects, backed by Hpricot, which I very creatively named > rspec_hpricot_matchers. It''s not a drop-in replacement for > rspec_on_rails'' have_tag(): no substitution values, Hpricot''s CSS > selectors aren''t identical to assert_select''s, and with_tag() has been > replaced by nested calls to have_tag(). But it''s pretty close and even > enjoys a few benefits over the standard implementation. > > I finally got around to registering a project on RubyForge and pushing > a gem, so it is now available with just: > > gem install rspec_hpricot_matchers > > If you''re interested, the source is hosted on github at: > > github.com/pd/rspec_hpricot_matchers > > I''m using this both in isolated XML-related libraries and in my Rails > projects, and I haven''t come up with any features I want lately, so > it''s reasonably stable in my experience. Usage examples are available > in the README, and the specs are simple enough to be another good set > of examples. > > Suggestions, patches and angry flames about list spamming are all welcome. > > Thanks > > Kyle > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > rubyforge.org/mailman/listinfo/rspec-users >-- coreyhaines.com The Internet''s Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: rubyforge.org/pipermail/rspec-users/attachments/20080402/8a4b2761/attachment.html
Phlip
2008-Apr-04 04:19 UTC
[rspec-users] [ANN] rspec_hpricot_matchers 1.0: have_tag on hpricot
Corey Haines wrote:> A few weeks ago, I put together a little project that provides a > have_tag() matcher look-alike that can be used outside of Rails > projects, backed by Hpricot, which I very creatively named > rspec_hpricot_matchers.I bet it can easily do something like this (if you rspeckers will excuse the dreaded word "assert"!): def assert_all_embedded_images assert_any_xpath :img do |img| assert_public_image_file img[:src] false # :keep looping! end end def test_find_all_embedded_images get :some_action # a Rails functional test assert_all_embedded_images end def assert_public_image_file(src, line = nil) src.sub!(/^\//, '''') # RailsRoot = Pathname.new(RAILS_ROOT) image_file = RailsRoot + ''public'' + src # this file must be where the server and browser can see it assert_file(line){ image_file } end Those assertions scan every image in a page and ensure a file with the correct name appears in ./public/images/. (Our artists have recently been sending us new assets, and I didn''t feel like manually checking we copied in all the right images...) The :img is a shortcut for the XPathic ''descendent-or-self::img'', and the img[:src] is naturally a shortcut for the <img src=''''> attribute. Those assertions - assert_xpath, assert_any_xpath, etc - work interchangeably with REXML, Hpricot, or Libxml for their parser. You just pick the one you want by adding to your setup() a call like invoke_rexml, invoke_hpricot, or invoke_libxml. Each provides various trades-off, but at work we have fixated on Libxml, naturally, because we use hundreds of these assertions, so we need its speed. Also, Libxml strictly enforces the Transitional XHTML type that appears in all our DOCTYPEs. (gem install assert_xpath, but I haven''t documented the libxml variant yet...) My little trick with the image files is only the start of assert_xpath''s abilities. You can also call it from inside an rspec; you just have to include its modules. And, like any of my assertions, it provides a detailed, comprehensive diagnostic if it fails. -- Phlip