Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

"do something, then do something else" kind of mock #736

@Nowaker

Description

@Nowaker

Mocha example:

@obj.stubs(:method).returns(1).then.raises

I propose a feature:

@obj.stub(:method).and_return(1).and_return(2).and_raise

When there are multiple and_* calls on the mock, they are called one after another. The last one is called indefinitely.

I'm sorry if something like that is already implemented. I wasn't able to find anything about that in the docs or Google. I merely found this gist... which is ugly compared to mocha approach. https://gist.github.com/dlchet/1847708

    Foo.stub(:bar) do
      @counter += 1
      pp @counter
      raise Exception if @counter < 2
      "hello"
    end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions