On 6/07/2014 9:23 am, Antonio Antillon wrote:
Hi Arup,
try doing this in your foo_spec.rb
describe Foo do
before { allow(Foo).to receive(:baz).and_return(20) }
# all other lines as they are
end
should be
allow_any_instance_of(Foo).to receive(:baz).and_return(20)
... right?
Xavier
(obligatory reminder of this paragraph from the docs:
https://relishapp.com/rspec/rspec-mocks/v/3-0/docs/working-with-legacy-code/any-instance
This feature is sometimes useful when working with legacy code, though
in general we
discourage its use for a number of reasons:
* The|rspec-mocks|API is designed for individual object instances, but
this feature operates on entire classes of objects. As a result
there are some sematically confusing edge cases. For example,
in|expect_any_instance_of(Widget).to receive(:name).twice|it isn't
clear whether each specific instance is expected to
receive|name|twice, or if two receives total are expected. (It's the
former.)
* Using this feature is often a design smell. It may be that your test
is trying to do too much or that the object under test is too complex.
* It is the most complicated feature of|rspec-mocks|, and has
historically received the most bug reports. (None of the core team
actively use it, which doesn't help.)
)
On Sun, Jul 6, 2014 at 3:58 AM, Arup Rakshit <[email protected]
<mailto:[email protected]>> wrote:
Look at the code below :-
#!/usr/bin/env ruby
class Foo
def baz
11
end
end
Now my Rspec code :-
require_relative "../test.rb"
describe Foo do
before { Foo.any_instance.stub(:baz).and_return(20) }
it "defines #foo dynamically" do
expect_any_instance_of(Foo).to receive(:baz).and_return(20)
subject.baz
end
end
And finally I got :-
Deprecation Warnings:
Using `any_instance` 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:4: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.04004 seconds (files took 0.47731 seconds to load)
1 example, 0 failures
arup@linux-wzza:~/Ruby>
What else way I can write this ?
--
================
Regards,
Arup Rakshit
================
Debugging is twice as hard as writing the code in the first place.
Therefore,
if you write the code as cleverly as possible, you are, by
definition, not
smart enough to debug it.
--Brian Kernighan
--
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]
<mailto:rspec%[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/29269646.tYJQcMUKxg%40linux-wzza.site.
For more options, visit https://groups.google.com/d/optout.
--
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]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/CANS3KkK%2BOX_A%3D%2Br8xGcLKK%2BPt%3DFs42hDhKW5%3DHpf4cK2dfG9FQ%40mail.gmail.com
<https://groups.google.com/d/msgid/rspec/CANS3KkK%2BOX_A%3D%2Br8xGcLKK%2BPt%3DFs42hDhKW5%3DHpf4cK2dfG9FQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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/53B97B1B.1040408%40xaviershay.com.
For more options, visit https://groups.google.com/d/optout.