|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
be_none and be_any don't seem to work properlyHi all!
I'm testing some named scopes. I use be_all(&:some_predicate) to test if all the elements in the collection are valid, which works, but when I try to test the inverse, it fails. You can see the complete code at: http://gist.github.com/213636 But in short: subject = User.active subject.should be_all(&:active) # works inverse = User.all - subject inverse.none?(&:active).should be_true # works inverse.should be_none(&:active) # doesn't work And also "inverse.should_not be_any(&:active)" doesn't work either And I cannot figure out why. The RDoc of rspec or rspec-rails don't mention be_none or be_any, so I would think that this would be straightforward. Anyone any ideas? Thanks in advance, Iain - iain.nl _______________________________________________ rspec-users mailing list rspec-users@... http://rubyforge.org/mailman/listinfo/rspec-users |
|
|
Re: be_none and be_any don't seem to work properlyOn Oct 19, 2009, at 2:12 PM, iain wrote: > Hi all! > > I'm testing some named scopes. I use be_all(&:some_predicate) to test > if all the elements in the collection are valid, which works, but when > I try to test the inverse, it fails. > > You can see the complete code at: http://gist.github.com/213636 > > But in short: > > subject = User.active > subject.should be_all(&:active) # works > > inverse = User.all - subject > inverse.none?(&:active).should be_true # works > inverse.should be_none(&:active) # doesn't work > > And also "inverse.should_not be_any(&:active)" doesn't work either > > And I cannot figure out why. The RDoc of rspec or rspec-rails don't > mention be_none or be_any, so I would think that this would be > straightforward. Anyone any ideas? I'm not certain, but I _think_ that the problem is the way you're setting up the factories. Try just creating the objects directly and see what happens: http://gist.github.com/215201 HTH, David > > Thanks in advance, > Iain - iain.nl > _______________________________________________ > rspec-users mailing list > rspec-users@... > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David _______________________________________________ rspec-users mailing list rspec-users@... http://rubyforge.org/mailman/listinfo/rspec-users |
|
|
Re: be_none and be_any don't seem to work properlyOn Oct 21, 5:45 pm, David Chelimsky <dchelim...@...> wrote: > On Oct 19, 2009, at 2:12 PM, iain wrote: > > > > > Hi all! > > > I'm testing some named scopes. I use be_all(&:some_predicate) to test > > if all the elements in the collection are valid, which works, but when > > I try to test the inverse, it fails. > > > You can see the complete code at:http://gist.github.com/213636 > > > But in short: > > > subject = User.active > > subject.should be_all(&:active) # works > > > inverse = User.all - subject > > inverse.none?(&:active).should be_true # works > > inverse.should be_none(&:active) # doesn't work > > > And also "inverse.should_not be_any(&:active)" doesn't work either > > > And I cannot figure out why. The RDoc of rspec or rspec-rails don't > > mention be_none or be_any, so I would think that this would be > > straightforward. Anyone any ideas? > > I'm not certain, but I _think_ that the problem is the way you're > setting up the factories. Try just creating the objects directly and > see what happens: > > http://gist.github.com/215201 > > HTH, > David > > > > > Thanks in advance, > > Iain - iain.nl > > _______________________________________________ > > rspec-users mailing list > > rspec-us...@... > >http://rubyforge.org/mailman/listinfo/rspec-users > > Cheers, > David > > _______________________________________________ > rspec-users mailing list > rspec-us...@...://rubyforge.org/mailman/listinfo/rspec-users Nope, no difference. The arrays with records are all fine when I inspect them, just as I would expect. The message "expected any? to return false" looks okay, so the only thing I can imagine is that it doesn't send it to the right receiver. I've made an inverse selection too, where I match be_any on subject, but to no avail. I've also tried it without named_scopes, again not changing the situation. But then again, why should "all?" work, but "any?" or "none?" not? _______________________________________________ rspec-users mailing list rspec-users@... http://rubyforge.org/mailman/listinfo/rspec-users |
|
|
Re: be_none and be_any don't seem to work properlyOn 21 Oct 2009, at 16:45, David Chelimsky wrote:
> On Oct 19, 2009, at 2:12 PM, iain wrote: >> I use be_all(&:some_predicate) to test if all the elements in the >> collection are valid, which works, but when I try to test the >> inverse, it fails. > I'm not certain, but I _think_ that the problem is the way you're > setting up the factories. I don't think be_all(&:some_predicate) actually works at all, except in the accidental sense that Enumerable#all indiscriminately returns true as long as all of the entries in the collection are truthy. At the moment it looks like dynamic predicate matchers like be_all completely ignore their block argument (&:some_predicate doesn't get rolled into *args) so you just get the default blockless behaviour of the underlying predicate. I've reported and patched this on Lighthouse: https://rspec.lighthouseapp.com/projects/5645-rspec/tickets/905 Cheers, -Tom _______________________________________________ rspec-users mailing list rspec-users@... http://rubyforge.org/mailman/listinfo/rspec-users |
| Free embeddable forum powered by Nabble | Forum Help |