On 04/08/15 19:54, Hleb Valoshka wrote:
> Hi team.
>
> I'm using transpec to convert rspec syntax to rspec3, but it seems
> that it's not enough. I need help to properly convert such pieces:
>
> == rspec 2.14 syntax ==
> describe Ridley::ClientResource do
> subject { described_class.new(double('registry')) }
>
> describe "#regenerate_key" do
> let(:client_id) { "rspec-client" }
> before { subject.stub(find: nil) }
>
> context "when a client with the given ID does not exist" do
> before { subject.should_receive(:find).with(client_id).and_return(nil) }
>
> it "raises a ResourceNotFound error" do
> expect {
> subject.regenerate_key(client_id)
> }.to raise_error(Ridley::Errors::ResourceNotFound)
> end
> end
> end
> end
>
> == after transpec ==
> describe Ridley::ClientResource do
> subject { described_class.new(double('registry')) }
>
> describe "#regenerate_key" do
> let(:client_id) { "rspec-client" }
> before { allow(subject).to receive_messages(find: nil) }
>
> context "when a client with the given ID does not exist" do
> before { expect(subject).to
> receive(:find).with(client_id).and_return(nil) }
>
> it "raises a ResourceNotFound error" do
> expect {
> subject.regenerate_key(client_id)
> }.to raise_error(Ridley::Errors::ResourceNotFound)
> end
> end
> end
> end
> ====
>
> The problem that code in before {} does not work, and ...Mock... error
> raised instead of expected one.
Can you paste the full error please?
> How such code should look to work with rspec3?
The 'after transpec' code looks fine, although the combination of a stub and a
mock of the same method is a little odd.
--
Matijs
Attachment:
signature.asc
Description: OpenPGP digital signature