|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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/. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
SSdtIG5vdCBleHBlcnQgb2YgQkREIGJ1dCBJIHRoaW5rIHRoYX QgeW91IHNob3VsZCB0ZXN0IHRo
ZXNlIDIgY2FzZXMKc2VwYXJhdGVseS4gSSBndWVzcyB0aGF0IH lvdXIgbWV0aG9kIGRvZXNuJ3Qg cmV0dXJuIEFycmF5IG9yIG5pbCBpbgpyYW5kb20gd2F5IDopLi BKdXN0IHNwbGl0IGl0IGludG8g dHdvIGV4cGVjdGF0aW9ucyAoaXQgInNob3VsZCByZXR1cm4KQX JyYXkgd2hlbi4uLiIsIGl0ICJz aG91bGQgcmV0dXJuIG5pbCB3aGVuLi4uIikuIEkgY2FuJ3QgdG hpbmsgYWJvdXQKcmVhbCBuZWVk IHRvIGhhdmUgdGhpcyBmdW5jdGlvbmFsaXR5IChlaXRoZXIub3 Iub3IpIGFuZCB5b3VyIGV4YW1w bGUKZG9lc24ndCBzaG93IG1lIGl0LgoKLS0gClJhZG9zs2F3IE J1s2F0CgpodHRwOi8vcmFkYXJl ay5qb2dnZXIucGwgLSBt82ogYmxvZwo= |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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/. |
|
![]() |
| Outils de la discussion | |
|
|