rspec/rspec-mocks — pull request #429 by mjezzi (2013-10-08 22:53:55+00:00)
Title: Feature for specific argument constraints (ex/ double.stub(:foo).with_fourth_argument(...))

I wanted to propose a new feature for rspec that allows an argument constraint style for a specific argument.

So, instead of:

```ruby
it "verifies one part" do
mock.should_receive(:method).with(value, anything, anything, value, anything)
...
end

it "verifies the other part" do
mock.should_receive(:method).with(anything, value, anything, anything, anything)
...
end

it "verifies yet some other part" do
mock.should_receive(:method).with(anything, anything, value, anything, anything)
...
end
```

I'd like it to be:

```ruby
it "verifies one part" do
mock.should_receive(:method).with_first_argument(value)
...
end

it "verifies the other part" do
mock.should_receive(:method).with_second_argument(value)
...
end

it "verifies yet some other part" do
mock.should_receive(:method).with_third_argument(value)
...
end
```

Some of the benefits

- It's easier to read
- Tests won't need to be updated if you add additional parameters to a method. With the current style of using _anything_, if I were to add a parameter to a method, I would then have to update all my with(...) constraints to include another _anything_ argument. This feature eliminates the need to rework the existing tests.

This pull request includes a working implementation that's tested, but I don't think it's all the way there. Before putting more time into the implementation, I first wanted to get some feedback from the rspec team to see if you would accept a feature like this. If the team does like it, I would love to get it to the point that meets the rspec team's standards, and also would love to hear suggestions regarding any implementation ideas.

Thanks!
Mike