Add the ability to pass a Fixnum to the match method #172

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
4 participants

Hello,

It's just a little pull request that allow users to pass a Fixnum to the match method. It's quite useful when we write specs for decorators in Rails application ; we want to check if the returned HTML element match a number of comments or articles for example.

I don't know if I have write the feature the right way, I don't used to use Cucumber so if I should edit something, please let me know.

I also allow myself to put minitest to the Gemfile because I'm a Fedora user and Fedora has got a bug, even with 1.9.3, we should gem install minitest or add it to the Gemfile. It's a bit of a pain because some features aren't passing.

Have a nice day.

Owner

dchelimsky commented Sep 23, 2012

Why not just do this?

it { should match /3/ }

@dchelimsky : When we use variables, there is no method to convert a Fixnum into a Regexp and convert every interger into strings is a bit of a pain. I think this implementation is not huge and add flexibility to th user. What do you think ?

Owner

dchelimsky commented Sep 23, 2012

@robin850 - I don't understand the problem you're trying to solve. Can you post an example of "When we use variables"? That use case isn't in the description above or in the cucumber features in the patch.

@dchelimsky : Of course, here an example :

describe GameDecorator, :type => :decorator do
  it "..." do
    game.scores.should match(game.home_team.score)
  end
end
Owner

myronmarston commented Sep 23, 2012

How about one of these?

game.scores.should match(/#{game.home_team.score}/)
game.scores.should include(game.home_team.scores.to_s)

I think either will work for your case.

I'm going to close this, for a few reasons:

  • This change has the potential to break existing spec suites. The match matcher isn't just for regular expressions; it's for any object that implements #match?, and it's documented as such. That means that some users may have custom domain objects that implement #match? and accept fixnums, and they may use this matcher with it. Converting the fixnum to a regexp would break there specs.
  • This begs the question, what's special about fixnums? Should we convert floats, symbols, dates, times, etc to regexps? This is a business we don't want to be in.
  • If you need custom matcher behavior, then you can easily write a custom matcher--RSpec already has a rich API for that. We're happy to change the existing matchers and/or add a new one when it is broadly useful to many users and won't break existing spec suites, but this doesn't seem like something that many users would want (especially given how easy it is to use of my two examples above).
Contributor

alindeman commented Sep 23, 2012

What about?

describe GameDecorator, :type => :decorator do
  it "..." do
    game.scores.should include(game.home_team.score.to_s)
  end
end

That seems more intention-revealing to me as well.

@myronmarston @alindeman : Okay, sorry for disturbing. I thought call to_s was a bit of a pain but why not. ;) Have a nice day.

Owner

myronmarston commented Sep 23, 2012

@robin850 -- no need to apologize! I know it can be intimidating to submit a patch to an open source project and re-reading my response above, it came across as a bit dismissive, which I didnt intend (I was in a hurry to type the response before heading out the door). We hope to see more contributions from you in the future!

@myronmarston : no problem ! Not your bad at all. I'm happy to contribute to this project ; we can't always see our PR merged and I'm happy to see that you only merge useful things. I will contribute to Rspec projects, there is no problem ! Glad to help you. :)

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