On Thursday, July 3, 2014 9:49:56 PM UTC+5:30, Aaron Kromer wrote:
>
> Arup,
>
> Can you post your spec and exception. These should work on 2.14. If you
> are on RSpec 3, you need to either switch to the new syntax (
> https://www.relishapp.com/rspec/rspec-mocks/v/3-0/docs/basics/allowing-messages)
>
> or configure the old syntax (
> https://www.relishapp.com/rspec/rspec-mocks/v/3-0/docs/old-syntax).
>
> Here is a sample with the new syntax:
>
> allow(obj).to receive(:message).and_return(value)
>
> Cheers
>
Code :-
#!/usr/bin/env ruby
require 'ostruct'
class Foo
def intialize
#..
end
def meth
OpenStruct.new(suml: sum, mul: multiplication)
end
private
def sum(enum)
enum.inject(:+)
end
def multiplication(enum)
enum.inject(:*)
end
end
Rspec :
require_relative "../test.rb"
describe Foo do
before do
subject.should_receive(:sum).and_return(12)
subject.should_receive(:multiplication)
end
describe "#meth" do
it "return an OpenStruct instance" do
expect(subject.meth).to be_instance_of(OpenStruct)
end
end
end
And finally -
arup@linux-wzza:~/Ruby> rspec spec/test_spec.rb
.
Deprecation Warnings:
Using `should_receive` from rspec-mocks' old `:should` syntax without
explicitly enabling the syntax is deprecated. Use the new `:expect` syntax
or explicitly enable `:should` instead. Called from
/home/arup/Ruby/spec/test_spec.rb:5:in `block (2 levels) in <top
(required)>'.
If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
1 deprecation warning total
Finished in 0.00175 seconds (files took 0.13547 seconds to load)
1 example, 0 failures
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/64c0b722-7585-4903-8926-5a4d350a55b3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.