Permalink
Commits on Mar 12, 2013
  1. add Expectation#including_subclasses

    normally, stubbing a class method on a superclass simply makes
    calling that method on a subclass be an unexpected invocation.
    now you can optionally use the same stub for all subclasses
    committed Mar 12, 2013
Commits on Mar 7, 2013
  1. Ensure `Mockery` instance gets reset even if exception raised.

    It's unlikely but possible that an exception may be raised in
    `Mockery#teardown`. We should ensure that the `Mockery` instance gets
    reset if this happens.
    
    I'm not really happy with the way the test works, but without major
    changes this is the best I can do for now.
    
    Fixes #144.
    
    I saw this while investigating #142.
    floehopper committed Mar 7, 2013
  2. Make the `Hooks` module easier to unit test.

    Simplify the `Mockery` "API" that is used by the `Hooks` module i.e.
    there is no real need for `Hooks` to have direct access to the `Mockery`
    instance.
    floehopper committed Mar 7, 2013
Commits on Mar 6, 2013
  1. Safer restoration of stubbed method visibility. Fixes #141.

    It is possible for `Module#public`, `#protected` and `#private` to be
    redefined on descendant classes, so it' safer to use the original
    version of these methods on `Module` when restoring the visibility of
    stubbed methods.
    
    Rather than add a completely new set of tests for these scenarios, I
    have just embellished the existing tests. It's not ideal, because it
    makes it less clear what's going on, but I think it'll do.
    tmm1 committed with floehopper Mar 1, 2013
Commits on Mar 5, 2013
  1. Adapt tests to changes in MiniTest output.

    The Mocha integration tests are unfortunately dependent on the
    exact format of the test results output by MiniTest. This means that
    since the format changed in MiniTest v4.6.1, we have to change the
    regular expressions used to parse the output.
    
    It would be nicer to use named capture groups for the regular
    expression, but these only appear to be available in Ruby >= v1.9.
    floehopper committed Mar 5, 2013
  2. Make auto-activation of Test::Unit integration more resilient.

    This change is specifically to cope with the nasty re-defining of
    classes that is done by the `minitest-spec-rails` gem [1]. This
    confuses the Test::Unit version detection logic in Mocha and it thinks
    that the Ruby 1.8 standard library version of Test::Unit is being used
    when in fact there is no Test::Unit version present.
    
    I'm not completely sure why this has reared its head [2] with Rails 4
    and/or Ruby 2, and haven't checked carefully that this change is
    (a) completely logical; and (b) hasn't introduced any regressions,
    but it does seem to fix the problem. I'm going to push it now and try to
    track down any regressions separately - I'm pretty hopeful there won't
    be any.
    
    Note that it will be possible to avoid this problem in the future
    when we introduce the ability to manually activate specific test library
    integration and stop using the automatic activation.
    
    [1] metaskills/minitest-spec-rails#17
    [2] freerange#143
    floehopper committed Mar 5, 2013
Commits on Mar 4, 2013
  1. Merge pull request #140 from tmiller/master

    Use `require` instead of `load` with `test/unit/version`.
    
    Other gems also require `test/unit/version`. When mocha loads the
    same file it over writes the constant and causes a warning.
    
    I tried to reproduce the original problem [1] with more recent
    versions of the test-unit and mocha gems, but I ran into a
    different exception. This exception was fixed by adding a
    `gem "test-unit"` statement before the `require "test/unit"`
    statement.
    
    [1] http://floehopper.lighthouseapp.com/projects/22289-mocha/tickets/50#ticket-50-13
    floehopper committed Mar 4, 2013
Commits on Feb 26, 2013
Commits on Feb 24, 2013
  1. Use require instead of load with test/unit/version

      Other gems also require test/unit/version. When this gem loads the
    same file it over writes the constant and causes a warning.
    Tom Miller committed Feb 24, 2013
Commits on Feb 18, 2013
  1. Avoid deprecation warning in Bundler v1.2.4.

    I was seeing the following warning message:
    
        The source :rubygems is deprecated because HTTP requests are
        insecure. Please change your source to 'https://rubygems.org'
        if possible, or 'http://rubygems.org' if not.
    floehopper committed Feb 18, 2013
  2. Ensure all files have a newline at end-of-file.

    This is to avoid spurious git diffs.
    floehopper committed Feb 18, 2013
Commits on Feb 17, 2013
Commits on Feb 10, 2013
  1. Allow stubbing of private Kernel methods. Fixes #134.

    We were only testing stubbing of the public and protected methods on
    Object.
    
    Note that `#method_defined?` and `#instance_methods` include both public
    and protected, but not private methods.
    
    There are still a few methods that are awkward, but I've just
    excluded them from the tests for now.
    
    There's probably a better solution to this in 1.9 involving inheriting
    Mock from BasicObject instead of Object, but that's a job for another
    day.
    floehopper committed Feb 10, 2013
Commits on Jan 24, 2013
  1. Style tweak to ParameterMatchers::Includes#mocha_inspect implementation.

    I prefer unabbreviated variable names.
    floehopper committed Jan 24, 2013
  2. Changed `includes` API to accept more than on item to match against t…

    …he subject
    Simao Mata committed with floehopper Jan 24, 2013
Commits on Jan 23, 2013
Commits on Jan 22, 2013
Commits on Jan 10, 2013
Commits on Jan 8, 2013
  1. Add Google Analytics javascript to Mocha docs.

    Customising YARD templates is a bit obscure and this was the best I
    could come up with. The javascript appears as the last section within
    the content div, but before the footer div. Not ideal, but I think it
    should be ok.
    
    The tracking javascript is only displayed if the
    `GOOGLE_ANALYTICS_WEB_PROPERTY_ID` environment variable is set.
    floehopper committed Jan 8, 2013
Commits on Jan 4, 2013
Commits on Jan 3, 2013
  1. Make unit tests more robust to changes in environment. Fixes #121.

    @voxik wanted to run the tests by simply requiring the files rather than
    running the rake task. If the unit tests and acceptance tests are loaded
    in the same process and if a recent version of MiniTest is available,
    then `ExpectationErrorFactory.exception_class` was being set to
    `MiniTest::Assertion` at file load time and then later when the unit
    tests ran, the latter exception was being raised instead of the default
    `ExpectationError` exception. This causes a number of unit tests to
    fail.
    
    I have fixed this by changing the assertions to expect
    `ExpectationErrorFactory.exception_class`. I've also had to change
    `ExpectationErrorFactory.exception_class` to be set to the default at
    file load time to make this work.
    floehopper committed Jan 3, 2013
  2. Stubbing of methods re-declared with different visibilty. Fixes #109.

    Given a method which is re-declared with a different visibility lower
    down the ancestor chain, and given we stub the "version" of the method
    that is lower down the ancestor chain, we should ensure it is restored
    to its original visibility when it is "unstubbed".
    
    This was highlighted in #109 where the FileUtils module in Ruby 2.0
    declares the module-instance methods as private and then re-declares
    the module-class methods as public [1]. Even though this bug was
    highlighted in Ruby 2.0, it can happen in Ruby 1.8 or 1.9 if methods
    are declared in the same way.
    
    We've added a new acceptance test to demonstrate the bug and fixed it.
    The fix is to store and restore the method visibility whether or not
    we remove the stubbed method.
    
    Note that in Ruby 1.8.7 there is a warning about re-defining the method,
    but we can't see an easy way around this at the moment.
    
    [1]
    ruby/ruby@ace4630#L1R161
    chrisroos-and-floehopper committed Jan 3, 2013
Commits on Jan 2, 2013
  1. Add `Mock#responds_like_instance_of`. Fixes #119.

    This is useful if you have a class that is awkward to instantiate. The
    implementation uses `Class#allocate` to instantiate the responder
    _without_ calling the class' `#initialize` method. Having built the
    responder instance, the implementation is the same as for
    `Mock#responds_lie`.
    
    Thanks to @simao for the original suggestion.
    floehopper committed Jan 2, 2013
  2. Make whitespace consistent.

    floehopper committed Jan 2, 2013
  3. Make documentation example consistent with other examples.

    Elsewhere we are using `# =>` to display the expected output and not
    using `Test::Unit::Assertions`.
    floehopper committed Jan 2, 2013
Commits on Dec 4, 2012
  1. Tweaks to fix for #97.

    - I don't abbreviated variable names or variable names with digits in
      them, so I've got rid of `param_1`.
    
    - I've used some more case statements to simplify the code and hopefully
      make it more obvious what's going on. This also helped me find another
      edge case that we'd missed. See next bullet point.
    
    - Raise an argument error when someone supplies a single argument that
      is not a Hash.
    
    - Use some idiomatic Ruby to assign `key` & `value` in a single simpler
      statement.
    
    - Added a test for the case where more than two arguments are supplied
      and an argument error is raised.
    floehopper committed Dec 4, 2012
  2. Untested fix for #97: has_entry() does not work with an array as a ha…

    …sh value.
    
    Explicitly populate the key and value in different cases, rather than using flatten.
    Untested because I use rvm, which interferes with mocha unit testing
    ngokli committed with floehopper Nov 15, 2012
Commits on Nov 12, 2012
  1. Allow deprecation debug to be switched on from MOCHA_OPTIONS env var.

    I suspect there may be a lot of libraries out there that are requiring
    "mocha" directly will now be generating deprecation warnings. This
    should make it easier to find them.
    floehopper committed Nov 12, 2012
Commits on Nov 11, 2012