PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > rSpec - added a "either.or.or" Matcher
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
rSpec - added a "either.or.or" Matcher

Réponse
 
LinkBack Outils de la discussion
Vieux 25/05/2008, 16h01   #1
Matthew Rudy Jacobs
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut rSpec - added a "either.or.or" Matcher

Hey there guys,
not sure where I should discuss this really,
but I've created a ticket on LightHouse for rSpec.

Came across this problem;

"I have a method which either returns an array or a nil, how can I rspec
assert this?"

solution could be

[NilClass, Array].should include(Model.get_array_or_nil)

but that's rubbish.
I want;

Model.get_array_or_nil.should
either(be_an_instance_of(Array)).or(be_nil)

http://rspec.lighthouseapp.com/proje...her-or-matcher
should provide that.
(although it's built against the old svn repo, need to update it for
GIT)

Any thoughts?

MatthewRudy
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 25/05/2008, 17h48   #2
Rados³aw Bu³at
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: rSpec - added a "either.or.or" Matcher

SSdtIG5vdCBleHBlcnQgb2YgQkREIGJ1dCBJIHRoaW5rIHRoYX QgeW91IHNob3VsZCB0ZXN0IHRo
ZXNlIDIgY2FzZXMKc2VwYXJhdGVseS4gSSBndWVzcyB0aGF0IH lvdXIgbWV0aG9kIGRvZXNuJ3Qg
cmV0dXJuIEFycmF5IG9yIG5pbCBpbgpyYW5kb20gd2F5IDopLi BKdXN0IHNwbGl0IGl0IGludG8g
dHdvIGV4cGVjdGF0aW9ucyAoaXQgInNob3VsZCByZXR1cm4KQX JyYXkgd2hlbi4uLiIsIGl0ICJz
aG91bGQgcmV0dXJuIG5pbCB3aGVuLi4uIikuIEkgY2FuJ3QgdG hpbmsgYWJvdXQKcmVhbCBuZWVk
IHRvIGhhdmUgdGhpcyBmdW5jdGlvbmFsaXR5IChlaXRoZXIub3 Iub3IpIGFuZCB5b3VyIGV4YW1w
bGUKZG9lc24ndCBzaG93IG1lIGl0LgoKLS0gClJhZG9zs2F3IE J1s2F0CgpodHRwOi8vcmFkYXJl
ay5qb2dnZXIucGwgLSBt82ogYmxvZwo=

  Réponse avec citation
Vieux 25/05/2008, 18h15   #3
Craig Demyanovich
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: rSpec - added a "either.or.or" Matcher

Agreed. You should specify the different conditions under which the
method returns nil or an array in distinct examples. For example,
Array#reject! behaves this way. I'd write some examples like:

describe Array, "#reject!" do
before(:each) do
@letters = %w[b c d]
end

it "returns nil if no changes were made" do
@letters.reject! { |letter| letter < 'b' }.should be_nil
end

it "returns an array of values remaining after ones matching the
given criteria are rejected" do
@letters.reject! { |letter| letter > 'b' }.should == ['b']
end
end

By the way, the RSpec lists [ http://rubyforge.org/mail/?group_id=797
] would be a good place to discuss custom matchers.

Regards,
Craig

  Réponse avec citation
Vieux 25/05/2008, 19h40   #4
Matthew Rudy Jacobs
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: rSpec - added a "either.or.or" Matcher

Craig Demyanovich wrote:
>
> By the way, the RSpec lists [ http://rubyforge.org/mail/?group_id=797
> ] would be a good place to discuss custom matchers.


cheers Craig,
I have a feeling I don't do anything in any standard style.

will check out the mailing list,
unfortunately it's not tracked by ruby-forum.com, which is where I do
all my ruby discussion stuff

--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h26.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13144 seconds with 12 queries