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

RSpec terminology/syntax #14

Description

@Integralist

Just having a quick re-read of "The RSpec Book" and it seems that some of the test code that caused me a bit of confusion might not have if a clearer syntax was used.

double(), stub() and mock() are all effectively the same (they all create an instance of a MockClass).

The reason they exist is to indicate the different intent (rather than using double all the time).

Example give in the book was...

describe Statement do
  it "logs a message on generate()" do
    customer = stub('customer')
    customer.stub(:name).and_return('Aslak')
    logger = mock('logger')
    statement = Statement.new(customer, logger)
    logger.should_receive(:log).with(/Statement generated for Aslak/)
    statement.generate
  end
end

We know the stub method should be used on a Stub and the should_receive should be used on a Mock.

Admittedly that has made the existing code become clearer. But I like the idea of code having clear intention through better terminology.

Thoughts?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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