Hi all, I have an array of shipping_type''s being returned, and I want to see what is in there. In the past I have done: shipping_type.include?(Cart::SHIPPING_TYPE_REGULAR).should be_true This works, but looks really ugly.. It just doesn''t roll of the tongue very well. I then looked up the use of Predicates, which I had been using, but hadn''t realized: shipping_type.should be_include(Cart::SHIPPING_TYPE_REGULAR) This works, however the syntac of be_include looks very odd... Is there any way to do: shipping_type.should_include(Cart::SHIPPING_TYPE_REGULAR) How are other folks looking at the contents of an Array? Am I going around bassackwards on this? Eric ----------------------------------------------------- Eric Pugh | Principal | OpenSource Connections, LLC | 434.466.1467 | http://www.opensourceconnections.com
On 10/4/07, Eric Pugh <epugh at opensourceconnections.com> wrote:> Hi all, > > I have an array of shipping_type''s being returned, and I want to see > what is in there. In the past I have done: > > shipping_type.include?(Cart::SHIPPING_TYPE_REGULAR).should be_true > > This works, but looks really ugly.. It just doesn''t roll of the > tongue very well. I then looked up the use of Predicates, which I > had been using, but hadn''t realized: > > shipping_type.should be_include(Cart::SHIPPING_TYPE_REGULAR)You were close on this one, it should just be shipping_type.should include(Cart::SHIPPING_TYPE_REGULAR) It''s a special predicate just for working with arrays. Cheers, /Nick
Geoffrey Wiseman
2007-Oct-04 17:07 UTC
[rspec-users] Using Predicates to look at an array..
On 10/4/07, Eric Pugh <epugh at opensourceconnections.com> wrote:> > shipping_type.should be_include(Cart::SHIPPING_TYPE_REGULAR)This is what I usually do; I agree the syntax of be_include looks odd, as is true for some other predicates. OTOH, it''s hard to find a formulation that works well for all predicates. For instance: domain.should_valid doesn''t look as good as domain.should be_valid domain.should_include(x) looks better than domain.should be_include(x) Rspec could support both, which means you could select the one that "looks" right, I guess. That might lead to inconsistent usage. I can live with the current approach as well, looks odd, but it''s not a serious problem for me. - Geoffrey -- Geoffrey Wiseman -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071004/0a0f8fb6/attachment.html
David Chelimsky
2007-Oct-04 17:23 UTC
[rspec-users] Using Predicates to look at an array..
On 10/4/07, Geoffrey Wiseman <geoffrey.wiseman at gmail.com> wrote:> On 10/4/07, Eric Pugh <epugh at opensourceconnections.com> wrote: > > shipping_type.should > be_include(Cart::SHIPPING_TYPE_REGULAR) > > This is what I usually do; I agree the syntax of be_include looks odd, as is > true for some other predicates. > > OTOH, it''s hard to find a formulation that works well for all predicates. > For instance: > domain.should_valid doesn''t look as good as domain.should be_valid > domain.should_include(x) looks better than domain.should be_include(x) > > Rspec could support both, which means you could select the one that "looks" > right, I guess. That might lead to inconsistent usage. I can live with the > current approach as well, looks odd, but it''s not a serious problem for me.As Nick points out in this thread, rspec supports: collection.should include(some_item) Also, you can define your own predicate matchers very easily using the predicate_matchers collection: predicate_matchers[:be_able_to_cook] = [:can_cook?] chef.should be_able_to_cook => passes if chef.can_cook? Cheers, David> > - Geoffrey > -- > Geoffrey Wiseman > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On Oct 4, 2007, at 12:46 PM, Nick Sieger wrote:> On 10/4/07, Eric Pugh <epugh at opensourceconnections.com> wrote: >> Hi all, >> >> I have an array of shipping_type''s being returned, and I want to see >> what is in there. In the past I have done: >> >> shipping_type.include?(Cart::SHIPPING_TYPE_REGULAR).should >> be_true >> >> This works, but looks really ugly.. It just doesn''t roll of the >> tongue very well. I then looked up the use of Predicates, which I >> had been using, but hadn''t realized: >> >> shipping_type.should be_include(Cart::SHIPPING_TYPE_REGULAR) > > You were close on this one, it should just be > > shipping_type.should include(Cart::SHIPPING_TYPE_REGULAR) > > It''s a special predicate just for working with arrays.Isn''t it a general predicate for all foo? (boolean) methods? class Object def foo? true end end Object.new.should be_foo Doesn''t that work, as well? Scott
David Chelimsky
2007-Oct-04 17:32 UTC
[rspec-users] Using Predicates to look at an array..
On 10/4/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote:> > On Oct 4, 2007, at 12:46 PM, Nick Sieger wrote: > > > On 10/4/07, Eric Pugh <epugh at opensourceconnections.com> wrote: > >> Hi all, > >> > >> I have an array of shipping_type''s being returned, and I want to see > >> what is in there. In the past I have done: > >> > >> shipping_type.include?(Cart::SHIPPING_TYPE_REGULAR).should > >> be_true > >> > >> This works, but looks really ugly.. It just doesn''t roll of the > >> tongue very well. I then looked up the use of Predicates, which I > >> had been using, but hadn''t realized: > >> > >> shipping_type.should be_include(Cart::SHIPPING_TYPE_REGULAR) > > > > You were close on this one, it should just be > > > > shipping_type.should include(Cart::SHIPPING_TYPE_REGULAR) > > > > It''s a special predicate just for working with arrays. > > Isn''t it a general predicate for all foo? (boolean) methods? > > class Object > def foo? > true > end > end > > Object.new.should be_foo > > Doesn''t that work, as well?Sure it does, but be_include sounds icky. That''s the point of this thread, I believe.> > Scott > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Is there a way to have Autotest ignore a directory? I am working on a project that involves code generation and some spec stub files are created. This causes Autotest to run over and over. Ideally I would like to be able to say something like autotest --ignore /generated_output or have an entry in my .autotest file that told autotest to always ignore that directory. Thank you, Matt Margolis
Then it is a matter of changing your code or adding a .autotest like so: Autotest.add_hook :run do |at| at.exceptions = /generated_output/ end This allows you to ignore directories that match a regexp. Unfortunately, there is no hook in Autotest to allow you to ignore single file regexp which I need to ignore flymake.rb files when running emacs On 10/4/07, Matt Margolis <matt at mattmargolis.net> wrote:> > Is there a way to have Autotest ignore a directory? I am working on a > project that involves code generation and some spec stub files are > created. This causes Autotest to run over and over. Ideally I would > like to be able to say something like > autotest --ignore /generated_output > or have an entry in my .autotest file that told autotest to always > ignore that directory. > > Thank you, > Matt Margolis > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071009/f500c94a/attachment.html