[rspec-users] rspec-users Digest, Vol 84, Issue 1

Oliver Jesus oliverjesus2008 at yahoo.com
Mon Jun 10 01:47:18 UTC 2013



--- On Fri, 6/7/13, rspec-users-request at rubyforge.org <rspec-users-request at rubyforge.org> wrote:

From: rspec-users-request at rubyforge.org <rspec-users-request at rubyforge.org>
Subject: rspec-users Digest, Vol 84, Issue 1
To: rspec-users at rubyforge.org
Date: Friday, June 7, 2013, 10:08 AM

Send rspec-users mailing list submissions to
    rspec-users at rubyforge.org

To subscribe or unsubscribe via the World Wide Web, visit
    http://rubyforge.org/mailman/listinfo/rspec-users
or, via email, send a message with subject or body 'help' to
    rspec-users-request at rubyforge.org

You can reach the person managing the list at
    rspec-users-owner at rubyforge.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of rspec-users digest..."


Today's Topics:

   1. Fuzzy should_receive matching (Alexander Baronec)
   2. Re: Fuzzy should_receive matching (David Chelimsky)
   3. Re: RSpec 2, Rails 3, and SSL routes (Aashish Kiran)
   4. Re: Fuzzy should_receive matching (Alexander Baronec)
   5. Error uccored while evaluating nil.collect (Oliver Jesus)


----------------------------------------------------------------------

Message: 1
Date: Thu, 30 May 2013 11:44:19 +0400
From: Alexander Baronec <abonec at gmail.com>
To: rspec-users <rspec-users at rubyforge.org>
Subject: [rspec-users] Fuzzy should_receive matching
Message-ID:
    <CAKcJw60A1mJR3yJevHrYnsDKjoPtkuDDQr6j1fgOyYD055qQ=Q at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hello.
I have a test problem when I should test arguments in method not by exact
matching buy with fuzzy matching.

For example I have this test:

require 'rspec'

describe do
  it do
    o = Object.new
    o.should_receive(:api_send).with mode: :say

    o.api_send mode: :say, time: Time.now + rand(1..10), bans: { login1:
{time: Time.now, expiration: Time.now + 100}}
  end
end

I want helper to test that method api_send receive mode: :say, time:
Time.now + rand(1..10), bans: { login1: {time: Time.now, expiration:
Time.now + 100}} but I do not care about what time exactly is.

I want something like

inspect_api o, mode: :say, time: Time, bans: { login:1: {time: Time,
expiration: Time}}

Best regards.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20130530/169a96a3/attachment-0001.html>

------------------------------

Message: 2
Date: Thu, 30 May 2013 07:11:31 -0500
From: David Chelimsky <dchelimsky at gmail.com>
To: rspec-users <rspec-users at rubyforge.org>
Subject: Re: [rspec-users] Fuzzy should_receive matching
Message-ID:
    <CAKw-oWR2PuzGcd511hQOoT4uhs1fUJEL7ebK3YDuY8sEGPKM2Q at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

On Thu, May 30, 2013 at 2:44 AM, Alexander Baronec <abonec at gmail.com> wrote:

> Hello.
> I have a test problem when I should test arguments in method not by exact
> matching buy with fuzzy matching.
>
> For example I have this test:
>
> require 'rspec'
>
> describe do
>   it do
>     o = Object.new
>     o.should_receive(:api_send).with mode: :say
>
>     o.api_send mode: :say, time: Time.now + rand(1..10), bans: { login1:
> {time: Time.now, expiration: Time.now + 100}}
>
  end
> end
>
> I want helper to test that method api_send receive mode: :say, time:
> Time.now + rand(1..10), bans: { login1: {time: Time.now, expiration:
> Time.now + 100}} but I do not care about what time exactly is.
>
> I want something like
>
> inspect_api o, mode: :say, time: Time, bans: { login:1: {time: Time,
> expiration: Time}}
>

See docs:

http://rubydoc.info/gems/rspec-mocks/file/README.md#Argument_Matchers
http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/ArgumentMatchers#hash_including-instance_method

(the info in the 2nd link needs to be added to the first - sorry)

You could do either of:

    o.should_receive(:api_send).with hash_including(mode: :say)
    o.should_receive(:api_send).with mode: :say, time: instance_of(Time),
:bans { login1: {time: instance_of(Time), expiration: instance_of(Time) }

HTH,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20130530/3d4f29ef/attachment-0001.html>

------------------------------

Message: 3
Date: Tue, 04 Jun 2013 13:01:48 +0200
From: Aashish Kiran <lists at ruby-forum.com>
To: rspec-users at rubyforge.org
Subject: Re: [rspec-users] RSpec 2, Rails 3, and SSL routes
Message-ID: <4b829209b1aacb393c24eef1f356fd99 at ruby-forum.com>
Content-Type: text/plain; charset=UTF-8

I too came across same situation (i.e., testing ssl request in rails 
with specs).
Thinking there should be a solution.

Thanks,
Aashish

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


------------------------------

Message: 4
Date: Wed, 5 Jun 2013 13:20:28 +0400
From: Alexander Baronec <abonec at gmail.com>
To: rspec-users <rspec-users at rubyforge.org>
Subject: Re: [rspec-users] Fuzzy should_receive matching
Message-ID:
    <CAKcJw61-STL8iXaLD_v77HXBO4QqRfZiE5WFbkkCfcmJpSBLjw at mail.gmail.com>
Content-Type: text/plain; charset="koi8-r"

Thx. It's exactly what I searched.


On Thu, May 30, 2013 at 4:11 PM, David Chelimsky <dchelimsky at gmail.com>wrote:

> On Thu, May 30, 2013 at 2:44 AM, Alexander Baronec <abonec at gmail.com>wrote:
>
>> Hello.
>> I have a test problem when I should test arguments in method not by exact
>> matching buy with fuzzy matching.
>>
>> For example I have this test:
>>
>> require 'rspec'
>>
>> describe do
>>   it do
>>     o = Object.new
>>     o.should_receive(:api_send).with mode: :say
>>
>>     o.api_send mode: :say, time: Time.now + rand(1..10), bans: { login1:
>> {time: Time.now, expiration: Time.now + 100}}
>>
>   end
>> end
>>
>> I want helper to test that method api_send receive mode: :say, time:
>> Time.now + rand(1..10), bans: { login1: {time: Time.now, expiration:
>> Time.now + 100}} but I do not care about what time exactly is.
>>
>> I want something like
>>
>> inspect_api o, mode: :say, time: Time, bans: { login:1: {time: Time,
>> expiration: Time}}
>>
>
> See docs:
>
> http://rubydoc.info/gems/rspec-mocks/file/README.md#Argument_Matchers
>
> http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/ArgumentMatchers#hash_including-instance_method
>
> (the info in the 2nd link needs to be added to the first - sorry)
>
> You could do either of:
>
>     o.should_receive(:api_send).with hash_including(mode: :say)
>     o.should_receive(:api_send).with mode: :say, time: instance_of(Time),
> :bans { login1: {time: instance_of(Time), expiration: instance_of(Time) }
>
> HTH,
> David
>
>
>
> _______________________________________________
> 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/20130605/6c1781c5/attachment-0001.html>

------------------------------

Message: 5
Date: Fri, 7 Jun 2013 03:02:43 -0700 (PDT)
From: Oliver Jesus <oliverjesus2008 at yahoo.com>
To: rspec-users at rubyforge.org
Subject: [rspec-users] Error uccored while evaluating nil.collect
Message-ID:
    <1370599363.73231.YahooMailClassic at web162004.mail.bf1.yahoo.com>
Content-Type: text/plain; charset="iso-8859-1"

Hello, I am new to RSpec and I've got error something like this:?
You have a nil object when you didn't expect it!?
You might have expected an instance of Array.?
The error occurred while evaluating nil.collect?

In my controller:?

def new?
? ? @employee_mst = EmployeeMst.new?
? ? @branch_mst = BranchMst.all(:group => "branch_code")?
? ? @department_mst = DepartmentMst.all?

? ? respond_to do |format|?
? ? ? format.html # new.html.erb?
? ? ? format.xml ?{ render :xml => @employee_mst }?
? ? ? format.xml ?{ render :xml => @branch_mst }?
? ? ? format.xml ?{ render :xml => @department_mst } ? ? ??
? ? end?
? end?

In my RSpec controller:?

? describe "GET new" do?
? ? it "assigns a new employee_mst as @employee_mst" do?
? ? ? get :new?
? ? ? assigns(:employee_mst).should be_a_new(EmployeeMst)?
? ? end?
? end?


I think something is missing in RSpec controller, because I've add 4 lines of codes:?
? ? ?@branch_mst = BranchMst.all(:group => "branch_code")?
? ? ?@department_mst = DepartmentMst.all?
? ? ? format.xml ?{ render :xml => @branch_mst }?
? ? ? format.xml ?{ render :xml => @department_mst } ??

Please help me regarding this error. I greatly appreciated all those answers.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20130607/833281b3/attachment.html>

------------------------------

_______________________________________________
rspec-users mailing list
rspec-users at rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

End of rspec-users Digest, Vol 84, Issue 1
******************************************

I've seen the error. It's not in the rspec, it's on my model. Thank you for you help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20130609/2d25bd04/attachment-0001.html>


More information about the rspec-users mailing list