Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly call out args passed into any_instance stubs. #789

Merged
merged 1 commit into from Sep 24, 2014

Conversation

dblock
Copy link
Contributor

@dblock dblock commented Sep 23, 2014

See discussion in #717 (comment).

@JonRowe
Copy link
Member

JonRowe commented Sep 24, 2014

Heh, through a weird quirk, Ruby is parsing this as head, *tail = array, so it doesn't work. Maybe we should change this example to something made up, how about:

RSpec.describe "allow_any_instance_of" do
  it 'yields the receiver to the block implementation' do
    allow_any_instance_of(Array).to receive(:final) do |array, n|
      array.slice(n * -1, n).reverse
    end

    expect([1, 2, 3].final(2)).to eq([3, 2])
  end
end

@myronmarston
Copy link
Member

Alternately, we could use a different type than Array since arrays have splatting behavior.

@dblock
Copy link
Contributor Author

dblock commented Sep 24, 2014

I updated with using slice, which is already implemented as String#[start, length] and makes it a bit easier to parse.

@myronmarston
Copy link
Member

Thanks, @dblock. My concern now is that stubbing String#slice to make it do what String#slice already does isn't at all useful. Array#shuffle, on the other hand, is non-deterministic, so the original example is the kind of thing you might actually do, in order to control it for a test.

I guess the question becomes -- is there more documentation value in having an example that includes arguments? Or is there more documentation value in having an example that's something someone might actually do?

@dblock
Copy link
Contributor Author

dblock commented Sep 24, 2014

You should decide that, @myronmarston. I am happy to rewrite this as any function.

The question is really what users are looking for when they read the documentation.

Personally, I never paid attention to what the example was stubbing, but always paid attention to the syntax, the macros, and the arguments. I would make all examples it 'reticulates a spline' :)

@myronmarston
Copy link
Member

Personally, I never paid attention to what the example was stubbing, but always paid attention to the syntax, the macros, and the arguments. I would make all examples it 'reticulates a spline' :)

This is a good point. You've convinced me that while "realistic" examples might be a nice-to-have, it's far more important that we show syntax, APIs, etc.

myronmarston added a commit that referenced this pull request Sep 24, 2014
Explicitly call out args passed into any_instance stubs.
@myronmarston myronmarston merged commit 8f0a242 into rspec:master Sep 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants