have_same_elements_of proposal

View: New views
3 Messages — Rating Filter:   Alert me  

have_same_elements_of proposal

by Rodrigo Rosenfeld Rosas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

How about having this matcher along the default available matchers?

require 'set'
Spec::Matchers.define :have_same_elements_of do |expected|
   match do |actual|
     expected.to_set == actual.to_set
   end
end

Example:

[1,2].should have_same_elements_of([2,1])

Best Regards,

Rodrigo.

__________________________________________________
Faça ligações para outros computadores com o novo Yahoo! Messenger
http://br.beta.messenger.yahoo.com/ 
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: have_same_elements_of proposal

by Pat Maddox-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Already in.

[1,2].should =~ [2,1]

Pat

On Wed, Oct 28, 2009 at 4:44 PM, Rodrigo Rosenfeld Rosas
<lbocseg@...> wrote:

> How about having this matcher along the default available matchers?
>
> require 'set'
> Spec::Matchers.define :have_same_elements_of do |expected|
>  match do |actual|
>    expected.to_set == actual.to_set
>  end
> end
>
> Example:
>
> [1,2].should have_same_elements_of([2,1])
>
> Best Regards,
>
> Rodrigo.
>
> __________________________________________________
> Faça ligações para outros computadores com o novo Yahoo! Messenger
> http://br.beta.messenger.yahoo.com/
> _______________________________________________
> rspec-users mailing list
> rspec-users@...
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: have_same_elements_of proposal

by Rodrigo Rosenfeld Rosas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Excelent, Pat.

Is this operator documented somewhere?

Thank you,

Rodrigo.

Em 29-10-2009 00:16, Pat Maddox escreveu:

> Already in.
>
> [1,2].should =~ [2,1]
>
> Pat
>
> On Wed, Oct 28, 2009 at 4:44 PM, Rodrigo Rosenfeld Rosas
> <lbocseg@...>  wrote:
>    
>> How about having this matcher along the default available matchers?
>>
>> require 'set'
>> Spec::Matchers.define :have_same_elements_of do |expected|
>>   match do |actual|
>>     expected.to_set == actual.to_set
>>   end
>> end
>>
>> Example:
>>
>> [1,2].should have_same_elements_of([2,1])
>>
>> Best Regards,
>>
>> Rodrigo.
>>
>> __________________________________________________
>> Faça ligações para outros computadores com o novo Yahoo! Messenger
>> http://br.beta.messenger.yahoo.com/
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users@...
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
>>      
> _______________________________________________
> rspec-users mailing list
> rspec-users@...
> http://rubyforge.org/mailman/listinfo/rspec-users
>
>    

__________________________________________________
Faça ligações para outros computadores com o novo Yahoo! Messenger
http://br.beta.messenger.yahoo.com/ 
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users