Skip to content


Subversion checkout URL

You can clone with
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
This comparison is big! We’re only showing the most recent 250 commits
Commits on Nov 05, 2014
@mcmire mcmire Deprecate ensure_length_of for validate_length_of 7da90b1
@mcmire mcmire Rearrange some things in NEWS 090ae99
@mcmire mcmire Fix another warning 4c9dfa7
@mcmire mcmire Tweak allow_value failure message again
If no message is set and the matcher failed it formerly produced this

    Expected errors  when attr is set to "some value"...

Now it produces this message:

    Expected errors when attr is set to "some value"...
@mcmire mcmire Clean up acceptance tests a bit 0da09b2
Commits on Nov 06, 2014
@georgemillo georgemillo Typo fix 68a419a
@georgemillo georgemillo Updating documentation for `validate_length_of` c8bd4ce
@mcmire mcmire Fix association matchers + namespaced class_name
Fix `class_name` qualifier for association matchers so that if the
model being referenced is namespaced, the matcher will correctly resolve
the class before checking it against the association's `class_name`.

Take these models for instance:

module Models
  class Friend < ActiveRecord::Base

  class User < ActiveRecord::Base
    has_many :friends, class_name: 'Friend'

Here, the `has_many` is referring to Models::Friend, not just Friend.
Previously in order to test the association, you had to write:

    describe Models::User do
      it { should have_many(:friends).class_name('Models::Friend') }

Now, `have_many` will attempt to resolve the string given to
`class_name` within the context of the namespace first before treating
it as a reference to a global constant. This means you can now write

    describe Models::User do
      it { should have_many(:friends).class_name('Friend') }
@mcmire mcmire Clear schema cache after each test
When running unit tests in a random order, some tests may fail as the
columns hash within a model may not be in sync with the database. This
is because the columns hash is cached outside of the model, so removing
the model from the object space and then recreating that model won't
clear the columns hash.
@mcmire mcmire Run tests in a random order 1a5bbfa
@mcmire mcmire Upgrade 4.1 appraisal to Rails 4.1.7
This version fixes a bug with habtm and a namespaced class name so that
when the association looks up that class it will look inside the model
namespace instead of the global namespace.
Commits on Nov 18, 2014
@mcmire mcmire Fix validate_inclusion_of + with_message
It did not fail if the given message did not match the message on the
validation itself.
@mcmire mcmire Re-sort list of matchers in README
[ci skip]
Commits on Nov 19, 2014
@joshk joshk Use the new beta build env on Travis
faster vm boot times
more cpus
more ram
better network

docs coming soon
@mcmire mcmire Convert from Mocha to RSpec Mocks 3a76f93
@mcmire mcmire Refactor route specs a1dbca3
@mcmire mcmire Fix route matcher to fully work with non-string params
When using a string to specify controller and action, other parameters
needed to be specified as strings. This commit fixes `route` so that
this does not need to be the case.
@mcmire mcmire Ensure route matcher works with namespaced controllers 47a0392
Commits on Nov 20, 2014
@seanpdoyle seanpdoyle Add `validate_uniqueness_of_(:foo).allow_blank`
This re-applies fcbc16e.
@mcmire mcmire Add missing issue number [ci skip] 5a057a0
Commits on Nov 21, 2014
@mcmire mcmire Remove unnecessary file c41ec11
@mcmire mcmire set_the_flash => set_flash 0eb1091
@mcmire mcmire Deprecate set_the_flash in favor of set_flash c8fb802
@mcmire mcmire Reorganize set_session tests 5cfe040
@mcmire mcmire Bring set_session in line with set_flash
* Deprecate `set_session(:foo)` in favor of `set_session[:foo]`
* Make both #[] and #to optional (`should set_session` simply checks
  that the session is non-empty, `should'value')` checks
  that *any* value is 'value')
* Add support for regexps to #to
* Deprecate `should set_session(...).to(nil)` in favor of using
  `should_not set_session`
* Improve failure message
Commits on Dec 13, 2014
@mcmire mcmire Move uniqueness validation to ActiveRecord module cf76d74
@maurogeorge maurogeorge Add documentation to validates_presence_of on qualifier
[ci skip]
Commits on Dec 14, 2014
@mcmire mcmire Rename vars in delegate_method to match terminology in docs 1694c7b
Commits on Dec 15, 2014
@mcmire mcmire Improve certain names of tests for delegate_method f82d4ee
Commits on Dec 16, 2014
@aditya-kapoor aditya-kapoor Add with_prefix to delegate_method
Secondary author: Elliot Winkler <>
@mcmire mcmire Remove warning when running tests 502a2d3
@aditya-kapoor aditya-kapoor Correct link to set_flash in README
[ci skip]
Commits on Dec 17, 2014
@mcmire mcmire Revert "Remove unnecessary file"
This reverts commit c41ec11.
@mcmire mcmire Move test for validate_length_of to the right place 76c2f66
@mcmire mcmire Fix warnings spy so it doesn't capture more things than necessary b028927
@mcmire mcmire Fix warning for this file ab08fef
@mcmire mcmire Be better about looking for warnings on Travis b408287
@mcmire mcmire Improve failure messages for failure message matchers 8e049c1
Commits on Dec 24, 2014
@mcmire mcmire Add Appraisal for Rails 4.2 5aed533
Commits on Dec 25, 2014
@mcmire mcmire Fix test suite to properly tag example groups
When running unit tests we need to ensure that we are simulating how
other people will use the matchers as best we can. This means, for
instance, tagging any example groups that test controller matchers as
controller example groups.
@mcmire mcmire Ensure that we are req'd after rspec in tests
Currently before running unit tests we are getting auto-required before
rspec-rails is getting required. This is bad because we need to wait
until rspec-rails is loaded before injecting Shoulda::Matchers::* into
the current RSpec context, otherwise matchers that clash with
rspec-rails (such as `render_template` will get overridden).

This is happening when creating and booting the Rails application.
Bundler will auto-require any gems in the Gemfile. One of these gems is
ourselves (via the `gemspec` line). Since there aren't any dependencies
in the gemspec, there's no need for us to be in the Gemfile.

This means that we no longer have to explicit `include` Rails
ActionController template assertions in the tests for `render_template`
as they should get included automatically for us.
@mcmire mcmire Fix AC matcher tests for Rails 4.2
Modify helper methods provided by ControllerBuilder so that we use as
much of rspec-rails's controller example group capabilities as possible.
All of this can still be improved but this is a good start for now.
@mcmire mcmire Ensure that ActiveSupport warnings are being printed during tests 7dfbc5e
@mcmire mcmire Fix AR matcher tests for Rails 4.2 547d8b7
@mcmire mcmire Remove warning about #capture under 4.2+ c492416
@mcmire mcmire Fix acceptance tests where we should be using Bundler 8223420
@mcmire mcmire Add NEWS for Rails 4.2 [ci skip] 70faac7
@mcmire mcmire Bump top supported Ruby version to 2.1.5
[ci skip]
@mcmire mcmire Bump version to 2.8.0.rc1
[ci skip]
@mcmire mcmire Tweak NEWS
[ci skip]
@mcmire mcmire Documentation updates
[ci skip]
Commits on Dec 29, 2014
@iwz iwz Add Elliot Winkler to authors
Commits on Jan 04, 2015
@mcmire mcmire Configure Hound
* Prefer single quotes to double quotes
* Align method parameters with fixed indentation

[ci skip]
@mcmire mcmire Fix 3.1_1.9.2 appraisal so Travis does not error out 239487c
Commits on Jan 05, 2015
@lucianosousa lucianosousa uniqueness: Refactor code to set next value 9b252cc
Commits on Jan 20, 2015
@mcmire mcmire Add callback matchers to README 7f13068
@mcmire mcmire Add script to update a gem in all appraisals 45f3960
@barelyknown barelyknown Dependent qualifier now supports more values
* :destroy
* :delete
* :nullify
* :restrict
* :restrict_with_exception (Rails 4+)
* :restrict_with_error (Rails 4+)
* true
* false
Commits on Jan 23, 2015
@mcmire mcmire Use pry-nav for more debugging awesomeness 03977d1
@mcmire mcmire Use correct Hound config file 060df9e
@mcmire mcmire Improve output of fail_with_message matcher de111ea
@mcmire mcmire Fix test that was written poorly 84a366f
@mcmire mcmire Refactor submatcher logic in numericality matcher
...and also ComparisonMatcher
@mcmire mcmire Handle RangeErrors emitted now in ActiveRecord 4.2
In Rails 4.2, ActiveRecord was changed such that if you attempt to set
an attribute to a value and that value is outside the range of the
column, then it will raise a RangeError. For instance, an integer column
with a limit of 2 (i.e. a smallint) only accepts values between -32768
and +32767.

This means that if you try to do any of these three things, a RangeError
could be raised:

* Use validate_numericality_of along with any of the comparison
  submatchers and a value that sits on either side of the boundary.
* Use allow_value with a value that sits outside the range.
* Use validates_inclusion_of against an integer column. (Here we attempt
  to set that column to a non-integer value to verify that the attribute
  does not allow said value. That value is really a string version of a
  large number, so if the column does not take large numbers then the
  matcher could blow up.)

Ancillary changes in this commit:

* Remove ValidationMessageFinder and ExceptionMessageFinder in favor of
  Validator, StrictValidator, and ValidatorWithCapturedRangeError.
* The allow_value matcher now uses an instance of Validator under the
  hood. StrictValidator and/or ValidatorWithCapturedRangeError may be
  mixed into the Validator object as needed.
@mcmire mcmire Fix NEWS [ci skip] 938e8e6
@mcmire mcmire Put bug fixes above features [ci skip] eadbdf8
@mcmire mcmire Remove these from the docs 5bba211
@mcmire mcmire Remove all files from YARD except README and NEWS 630f0eb
@mcmire mcmire Add Rails 4.2 to Travis 1e4555e
@mcmire mcmire Bump version to 2.8.0.rc2 c9dc416
@mcmire mcmire Exclude site and gh-pages branches from Travis c47c574
@mcmire mcmire Refactor docs tasks a bit to match site tasks a409d8e
@mcmire mcmire Publish docs at /docs and not /
The new site will be published at / instead.
@mcmire mcmire Extract documentation tasks to a separate file 6925773
@mcmire mcmire Use custom github username in /docs/index.html for better testing 50b8cb8
@mcmire mcmire Fix docs:generate and docs:publish with custom latest version f4bfed3
@mcmire mcmire Add build/ and source/ to .gitignore 0f7bcfe
@mcmire mcmire Raise an error if version or latest_version missing 4da3ecf
@mcmire mcmire Make redirection to latest version domain-agnostic 5bc062e
@mcmire mcmire Update link to official documentation 3787559
@mcmire mcmire Prefix temporary gh pages dir with username 99a68fe
@mcmire mcmire Fix link to docs, again [ci skip] 63f9c03
Commits on Jan 30, 2015
@mcmire mcmire Bump version to 2.8.0 bbd0d5e
Commits on Feb 05, 2015
@mcmire mcmire Fix acceptance tests to actually remove gems 021d3d6
@mcmire mcmire Remove debugger, byebug, and web-console from 4.2
debugger and byebug cannot be present in Appraisals because they only
work on specific Ruby versions, and we test against a range of Ruby
versions. Hence, they can't be present in the Rails application that
gets generated in acceptance tests, either.

Also, we don't really need web-console to be there, it's just an extra
@mcmire mcmire Move test for uniqueness matcher to AR directory dff472e
@mcmire mcmire Test against RSpec 3 from now on
* Ruby 2.2 removed Minitest and Test::Unit from the standard library
  [[1]], [[2]]
* rspec-rails requires Test::Unit for Rails versions prior to 4.1 (which
  switched to Minitest)
* This doesn't work now, because we don't have Test::Unit present in the
  gem bundle
* RSpec 3.2.0 fixes this issue [[3]]

I don't really see this as a huge concern, since we were testing against
RSpec 2.99 for Rails < 4, and that has most of the changes that RSpec 3

[1]: ruby/ruby@f8c6a5d
[2]: ruby/ruby@96f5526
[3]: rspec/rspec-rails@999ebb7#diff-08d960c572ac094640dd183fa9641393R13
Commits on Feb 06, 2015
@mcmire mcmire Raise an error if no Appraisal is specified
If you attempt to run tests without specifying an Appraisal, then you
will be going off of the main Gemfile. The Gemfile is not guaranteed to
contain all of the dependencies necessary to run tests, so it is very
likely that you'll get an obscure error somewhere. Instead of letting
this happen, raise a specific error.
Commits on Feb 09, 2015
@mcmire mcmire Clean up Gemfile
* Remove Aruba and Bourne since we don't use them anymore
* Remove Rails from main Gemfile as it's already a dependency in each of
  the appraisals
* Tighten dependency on Rake to 10.x
* Move dependencies shared among appraisals to Appraisals
@mcmire mcmire Fail build if there are warnings f681d35
@mcmire mcmire Remove Rails 3.x, Ruby 1.9.2, Ruby 1.9.3
Ruby 1.9.3 will be end-of-lifed on February 23, 2015. We might as well
remove support for it now.
@mcmire mcmire Change behavior of should_not allow_value
Instead of asserting that any of the given value is an invalid value
(allowing good values to pass through), assert that *all* values are
invalid values (allowing good values not to pass through).

This means that this test which formerly passed now fails (assuming that
'good value' is a value that does not produce an invalid record):

    expect(record).not_to allow_value('good value', *bad_values)
@mcmire mcmire Remove auto-detection of Rails / test framework 1900071
@mcmire mcmire Use generic test framework for independent matchers test ab91bbf
@mcmire mcmire Remove deprecated matchers 55c8d09
@mcmire mcmire Add SetSessionOrFlashMatcher cc27723
@mcmire mcmire Remove set_the_flash in favor of set_flash 801f2c7
@mcmire mcmire Consolidate set_session and set_flash APIs
* Refactor so they both use SetSessionOrFlashMatcher internally
* Remove `set_session['key']` in favor of `set_session('key')`
* `set_flash['key'].to(nil)` no longer works if set_flash has never been
@mcmire mcmire Add support for Ruby 2.2
Secondary author: Luciano Sousa <>

Also, upgrade to rspec-rails 3.2.0 explicitly. (See
b7fe87a for an explanation of why 3.2.0
is necessary here.)
Commits on Feb 11, 2015
@mcmire mcmire Rewrite tests for validate_uniqueness_of
* The main problem I had with the old tests is that information that
  the reader didn't need to care about was not properly abstracted away.
  For instance, a helper method used by almost all tests will always
  create a model called Example, and will always use an attribute called
  "attr" (on which the validation is present). However, in some tests
  the class or attribute is referred to directly. The reader shouldn't
  have to care about either of these things, since they are constant --
  the tests should be readable enough so that this information is not
  necessary to understand the case being tested against.

* Speaking of this helper method, some of the tests used it and some
  didn't. Some defined their own helper methods to represent a
  particular case (`case_sensitive: true`, `allow_nil`, etc.). This is
  now fixed so that all but two tests use the same helper method to
  define a model. This model is completely customizable -- one can
  specify the type of the attribute being validated, the names and types
  of scoped attributes, etc.

* The tests around scoped attributes and different types are all
  basically the same, so they are now compressed into a shared context.

* Related to this, we no longer have to worry about setting a proper
  value for a scope attribute. One had to know which type that attribute
  had and come up with a reasonable default for that type. Now there is
  a helper method that worries about this automatically.

* Finally, we remove tests around case_insensitive against an integer
  attribute (these don't make any sense, and don't work).
@mcmire mcmire Tell Travis to only build pushes to master
The rest of the time, it will build changes to PR's.
@mcmire mcmire Remove Rubinius and JRuby from .travis.yml
Right now we tell Travis to ignore failed builds against Rubinius or
JRuby. This has been in place "temporarily" for more than 2 years, so we
effectively don't test against or support either runtime.
@mcmire mcmire Uniqueness: Add missing tests for scopes w/ datetime + Time
Here, we are basically testing the logic that generates a next value for
a scope attribute, in the case that that attribute is a Time object
instead of a DateTime object.
Commits on Feb 12, 2015
@mcmire mcmire Changes to CommandRunner
* Use full output instead of elided output on failure
* Refactor debugging code a bit
* Use :chdir option to Process.spawn instead of Dir.chdir
@mcmire mcmire Add support for Postgres
When running tests, you can now switch between running them against a
SQLite or PostgreSQL database. This is accomplished by modifying the
unit and acceptance tests so that when they generate and load the test
Rails application, database.yml is replaced with content that will
configure the database appropriately.
@mcmire mcmire Stop testing against columns unsupported by SQLite 74fa081
@mcmire mcmire Uniqueness: Support UUID columns that end in "f"
This commit fixes the uniqueness matcher so that when qualified with
`scoped_to` and one of the scopes is a UUID column that happens to end
in an "f", the matcher is able to generate a proper next value during
testing and doesn't error.
@mcmire mcmire Uniqueness: Add missing tests for text columns
Commits on Feb 13, 2015
@mcmire mcmire CommandRunner: if command fails, format it better
@guilhermeFranco guilhermeFranco Fix enum attribute name verification
Fix `define_enum_for` so that it actually tests that the attribute is
present in the list of defined enums, as you could fool it by merely
defining a class method that was the pluralized version of the attribute
name. In the same vein, passing a pluralized version of the attribute
name to `define_enum_for` would erroneously pass, and now it fails.
@mcmire mcmire Uniqueness: Support PG array columns for scopes
Please note that array columns do not work properly between Rails 4.0
and 4.2.

* If you set an array-of-date or array-of-time attribute to an
  array, it will fail to hold that value. This is an issue with
  timestamp-aware attributes and is fixed in Rails 4.2.

* Even if this worked, the uniqueness validator cannot cope with array
  columns, producing an invalid query. This will be fixed in 4.1.10.
Commits on Feb 14, 2015
@mcmire mcmire Uniqueness: Fix when scope set to nil beforehand
Switch the order of how the column type is detected so that string comes
last. This fixes a bug where if the scope was a text column but was set
to nil before running the matcher, the matcher would fail.
@mcmire mcmire Only Postgres columns respond to :array
Commits on Feb 16, 2015
@mcmire mcmire master == 3.0.0.alpha
There is no gem release associated with this commit, this is only so
that people who are testing against the master branch will see that the
version is not 2.8.0.

[ci skip]
Commits on Feb 17, 2015
Anthony Navarre + Elliot Winkler Uniqueness: Fix default behavior for case-insensitive models
If you have a model that has a uniqueness validation using
`case_sensitive: false`, and you are testing against but do not qualify
the matcher with `case_insensitive`, then the matcher will pass
unexpectedly. Take this model for instance:

    class Product < ActiveRecord::Base
      validates_uniqueness_of :name, case_sensitive: false

Currently, the following test passes. With this commit, it will now
(correctly) fail:

    describe Product do
      it { validate_uniqueness_of(:name) }
Commits on Feb 18, 2015
Anthony Navarre + Elliot Winkler allow_value: Raise error if attr sets value differently
`allow_value` will now raise a CouldNotSetAttribute error if the
attribute in question cannot be changed from a non-nil value to a nil
value, or vice versa. In other words, these are the exact cases in which
the error will occur:

* If you're testing whether the attribute allows `nil`, but the
  attribute detects and ignores nil. (For instance, you have a model
  that `has_secure_password`. This will add a #password= method to your
  model that is defined in a such a way that you cannot clear the
  password by setting it to nil -- nothing happens.)
* If you're testing whether the attribute allows a non-nil value, but
  the attribute fails to set that value. (For instance, you have an
  ActiveRecord model. If ActiveRecord cannot typecast the value in the
  context of the column, then it will do nothing, and the attribute will be
  effectively set to nil.)

What's the reasoning behind this change? Simply put, if you are assuming
that the attribute is changing but in fact it is not, then the test
you're writing isn't the test that actually gets run. We feel that this
is dishonest and produces an invalid test.
Commits on Feb 20, 2015
@seanpdoyle seanpdoyle Cache Bundler on Travis
With Container based CI, public projects can cache the results of
`bundle install`
Commits on Mar 01, 2015
@mcmire mcmire Upgrade pry to master version
The latest commit of pry removes a lot of annoying warnings.
Unfortunately a new release has not been issued yet, so just use the
master branch for now.
@mcmire mcmire Rename StrongParametersMatcher to PermitMatcher 2b0e1fb
@mcmire mcmire #permit was missing from the README 8d8f7a0
@mcmire mcmire Rewrite the tests for #permit
* Use `permit` directly instead of manually building the matcher
* Some tests were being tested by calling #matches? directly when they
  shouldn't have been, and some tests were duplicated
* Rename helper methods that define controllers to express intent better
* Don't make a global class (SimulatedError), keep the class local to
  the example group
* Use lambdas for that use `raise_error`
@mcmire mcmire Make Doublespeak specs runnable without Rails 878cfbd
@mcmire mcmire Doublespeak: Introduce a better MethodCall
MethodCall is used to represent a method call made on a double. It
stores the object the call was made on, the name of the method, any
arguments or block sent to the method, and the double itself. There were
quite a few places where we were using an (args, block) or (object,
args, block) tuple. We also already had a MethodCall class, and
additionally a MethodCallWithName class, and the two were basically the
same. These usages have all been collapsed.
@mcmire mcmire Doublespeak: Only store original method once
If a method for a class is doubled more than once within the same test
run, the original implementation of that method will change from double
to double, even if the double is deactivated correctly. Say we have two
distinct tests that both double the same method. Here is how that method
will be overridden as it goes along:

    A) START: original method
    B) ACTIVATE (1st test): method is doubled
    C) DEACTIVATE (1st test): calls original method (A)
    D) ACTIVATE (2nd test): original method (C) stored; method is again
    E) DEACTIVATE (2nd test): calls original method (C)

With this commit, this changes to:

    A) START: original method
    B) ACTIVATE (1st test): method is doubled
    C) DEACTIVATE (1st test): calls original method (A)
    D) ACTIVATE (2nd test): original method not stored again; method is
                            again doubled
    E) DEACTIVATE (2nd test): calls original method (A)
@mcmire mcmire Doublespeak: Proxies store return value in MethodCall 0300be8
@mcmire mcmire Doublespeak: Remove warnings when re-doubling methods
@mcmire mcmire Omit newest private modules from docs
[ci skip]
@mcmire mcmire Permit matcher now supports subparameters
Previously we were taking ActionController::Parameters and completely
overriding #require, forcing it to return `self`, i.e, the entire
ActionController::Parameters object. This meant that we broke its
functionality, which is to return a slice of the params hash instead.
The consequence of this is that attempting to call #permit on a slice of
the params hash obtained via #require would not work:

``` ruby
params =
  { "course" => { "foo" => "bar" } }

This commit fixes the permit matcher so that #require is proxied
instead, retaining the existing behavior.

This commit also adds a qualifier, #on, for asserting that your action
places a restriction on a slice of the params hash. The `permit` matcher
will properly track calls on child `params` instances. For example:

``` ruby
class UsersController < ActionController::Base
  def create


  def user_params
    params.require(:user).permit(:name, :age)

describe UsersController do
  it { should permit(:name, :age).for(:create).on(:user) }

If this fails, you'll get the following error message:

Expected POST #create to restrict parameters for :user to :name and :age,
but restricted parameters were :first_name and :last_name.
@dLobatog dLobatog Update copyright year in README b1e4c05
@mcmire mcmire Document allow_value + with_message with a regexp a453dcc
Commits on Mar 12, 2015
@cpytel cpytel Add "About thoughtbot" section to readme
* Move thanks to contributors to the top
* Remove credits section
* Introduce new "About thoughtbot" section.
Commits on Mar 13, 2015
@mcmire mcmire Run Travis on all branches again 9bbf7b0
@lucianosousa lucianosousa Update shoulda-matchers.gemspec
finishing drop support to ruby 1.9.x
Commits on Mar 15, 2015
Florence Foo validate_after_scope_change? use compact before retrieving max
Otherwise produces error "ArgumentError: comparison of NilClass with
String failed" if the resultant contains a combinations of strings and
Commits on Mar 29, 2015
@mcmire mcmire Improve failure messages for #fail_with_message_including
This improves our internal matcher so that it mirrors
#fail_with_message. In other words, when it fails it will now say:

    Expectation should have failed with:
      Some message goes here
    Actually failed with:
      Some other message goes here
    However, the expectation did not fail.
@mcmire mcmire Refactor specs for numericality matcher
Mainly, use some metaprogramming to add tests that combine the
qualifiers in various ways. This paves the way to add a #strict
qualifier and yet test its interaction with other qualifiers completely.
@maurogeorge maurogeorge Add documentation to validate_absence_of on qualifier
[ci skip]
@maurogeorge maurogeorge Add documentation to validate_acceptance_of on qualifier
[ci skip]
@maurogeorge maurogeorge Add documentation to validate_confirmation_of on qualifier
[ci skip]
@maurogeorge maurogeorge Add documentation to validate_exclusion_of on qualifier
[ci skip]
@maurogeorge maurogeorge Add documentation to validate_inclusion_of on qualifier
[ci skip]
@maurogeorge maurogeorge Add documentation to validate_length_of on qualifier
[ci skip]
@maurogeorge maurogeorge Fix documentation of validate_length_of with_message qualifier 53aa27b
@maurogeorge maurogeorge Add documentation to validate_uniqueness_of on qualifier
[ci skip]
@maurogeorge maurogeorge Add documentation to validate_numericality_of on qualifier
[ci skip]
Adam89 Added strict option to Numericality matcher 4e4c546
@mcmire mcmire Replace watchr with Guard
watchr has not been maintained for quite some time and no longer works
properly with Ruby 2.2.
@ignat-zakrevsky ignat-zakrevsky Fix links to callback matchers in README
[ci skip]
Commits on Apr 01, 2015
@mcmire mcmire Add instances of guard in various appraisals a5bc580
Commits on Apr 02, 2015
@maurogeorge maurogeorge The route matcher accepts a format as a symbol 15359eb
@mcmire mcmire Update NEWS as 3.0.0 isn't quite out yet 25b687c
Commits on Apr 03, 2015
@thavelick thavelick Added dependency installation guide
includes steps for Debian- and RedHat-based systems
@mcmire mcmire Update CONTRIBUTING
* Make the headers smaller
* Don't ask people to update the documentation
* Don't install Ruby version globally, just install it locally

[ci skip]
@takiy33 takiy33 Use pry-byebug instead of pry-nav 05a11ae
@mcmire mcmire Update installation instructions in README

* Mention RSpec before Minitest (since it's used more often)
* Fix instructions on generating YARD documentation automatically
* Make a new Contributing section
* Use "Shoulda Matchers", not shoulda-matchers
* Add notice that this is the README for the master branch

[ci skip]
Commits on Apr 04, 2015
@mcmire mcmire Add #on qualifier to numericality matcher
This is present in all other matchers through ValidationMatcher.
However, ValidateNumericalityOfMatcher does not inherit from
ValidationMatcher. (This happens to be okay, since
ValidateNumericalityOfMatcher contains submatchers and we have to make
sure to pass the context all the way through.)

Hat tip @sj26 for most of the content of this commit, as well as
@anujbiyani for another approach to this.
@jacobsimeon jacobsimeon Rename AssociationMatcher#join_table
Free up the `join_table` name so that users can specify a `join_table`
option when testing their associations.
@jacobsimeon jacobsimeon Explicitly test custom `:join_table` option #547
Some developers might want to pass a :join_table option to their HABTM
association declarations (e.g., `has_and_belongs_to_many :posts,
join_table: :users_and_their_posts). Those same developers, may want to
explicitly test the existence of the join table. Make this possible.
@jacobsimeon jacobsimeon Fix calls to old method name. f80b85f
@jacobsimeon jacobsimeon Add support for hbtm :join_table option
Rails supports declaring a `has_and_belongs_to_many` relationship with a
custom `:join_table` option and some developers want to assert that the
correct value is being used. Add `AssocationMatcher#join_table` to allow
developers to test the following:

1) That the :join_table option is being used for the relationship
2) That the *correct value* is being used
3) That the custom join table exists in the database
Commits on Apr 15, 2015
@mcmire mcmire Add Code of Conduct to CONTRIBUTING
[ci skip]
Commits on Apr 16, 2015
@maurogeorge maurogeorge Uniqueness matcher now works with boolean scopes 7c8e3f5
Commits on Apr 20, 2015
@maurogeorge maurogeorge Create the allow_values matcher
It is a alias to the actual allow_value matcher.
Commits on May 12, 2015
@mcmire mcmire Installation instructions apply only to master branch
[ci skip]
Commits on May 22, 2015
@mcmire mcmire Fail when no scopes on uniq matcher but scopes on validation
Change behavior of `validate_uniqueness_of` when the matcher is not
qualified with any scopes, but your validation is. Previously the
following test would pass when it now fails:

    class Post < ActiveRecord::Base
      validate :slug, uniqueness: { scope: :user_id }

    describe Post do
      it { should validate_uniqueness_of(:slug) }
@mcmire mcmire Add links to commits for items unassoc'd with a PR
[ci skip]
@mcmire mcmire Add missing items to NEWS for 3.0.0
[ci skip]
Commits on Jun 01, 2015
@lucasdavila lucasdavila Allow the use of matchers from multiple libs, for non rails projects.
* It changes shoulda-matchers to allow the integration with multiple
  libraries like active_model and active_record.

  For example, in a non Rails project isn't possible to use both
  validate_presence_of and validate_uniqueness_of matchers, because they
  are from different libraries (one from active_model and the other from
  active_record respectively).

  This change allow the integration with multiple libraries. fixes #710
@maurogeorge maurogeorge Add doc to join_table qualifier on have_and_belong_to_many matcher
[ci skip]
@lnikkila lnikkila Fix typo in `rescue_from` description.
Changes the description message into the imperative mood. Now RSpec’s
output makes more sense:

    should rescue from ActiveRecord::RecordInvalid
@mcmire mcmire Fix failure message for numericality matcher
Secondary author: Mauro George <>

Sometimes the failure message did not always provide the reason for
failure. For instance, given this validation:

    validates :ano, numericality: { only_integer: true, greater_than_or_equal_to: 1900 }

this test:

    it { should validate_numericality_of(:ano).is_greater_than_or_equal_to(1900) }

would fail with the following:

    Did not expect errors  when ano is set to 1900.000000000001, got error:

as you can see, the failure message doesn't contain the validation

In the process of making this fix, we changed how the matcher fails so
that it will so when the first submatcher fails, not the last. This
changes what the failure message looks like, but not the basic
functionality of the matcher itself.
@mcmire mcmire Bump version to 3.0.0.rc1 a3fb06c
Commits on Jun 13, 2015
@maurogeorge maurogeorge Run formatter documentation when running a single file
Today if we run a single file or spec like `callback_matcher_spec.rb` or
`callback_matcher_spec.rb:12` the formatter is the default dot.

With this config when we run a single file or spec the formatter is the
documentation and when we run the suite the formatter is the default dot.
Commits on Sep 22, 2015
@Lrcezimbra Lrcezimbra Added validate_absence_of and validate_acceptance_of fc78a2d
@maurogeorge maurogeorge Update RDoc of permit matchers according the new behavior.
In 3.0 the permit matcher require the definition of the params.

[ci skip]
@maurogeorge maurogeorge Add note about polymorphic associations on have_many
[ci skip]
@maurogeorge maurogeorge Remove cucumber.yml
Since we are using the RSpec for acceptance tests we no longer need this
@maurogeorge maurogeorge Drop support for RSpec 2 32c0e62
@mcmire mcmire List compatible gems/versions in README
[ci skip]
@mcmire mcmire Update internal list of supported versions
* 2.2.2 -> 2.2.3
* 2.1.5 -> 2.1.6
@voxik voxik Remove executable bit on CSS file 7a81150
Commits on Sep 23, 2015
@maurogeorge maurogeorge Document how to test conditional validations
Secondary-Author: Elliot Winkler <>

[ci skip]
@mcmire mcmire Manually autogenerate docs

* The guard-yard gem doesn't seem to work so well anymore. In fact, the
  problem is with `yard server` -- it doesn't seem to use our custom
  template files.

To satisfy the above:

* Instead of using Guard and guard-yard, use the fssm gem to manually
  watch various files.
* Instead of using `yard server`, run `yard doc`, which *does* honor our
  custom template files.
* You can run `rake autogenerate_docs` to make this happen; update the
  README accordingly.

[ci skip]
@maurogeorge maurogeorge works only if called before any other qualifier
In the 3.0.0 `set_flash[:foo].now` is no longer a valid syntax, only the
`[:foo]` is valid[1].

Since this can create a false positive when people updating, we will raise a
exception to make the things more explicit.

[1]: #752
@maurogeorge maurogeorge Stop handling AR RangeError when assign a attribute
Active Record 4.2.1 and upper no more raises a `RangeError` on the
assign, only at database level [1].

This will remove all code related to handling of Active Record `RangeError`.

Also, this upgrades the internal dependency on Rails 4.2 to 4.2.3.

[1]: rails/rails@fed7d7c
@AlexVPopov AlexVPopov Fix docs for `render_template` with partial
If a partial's is not prefixed with an underscore a test would fail with
a similar error message, as:

> Failure/Error: it { should render_template(partial: 'form') }
       expecting partial <form> but action rendered <["expenses/_form", "_form"]>.
       Expected {"expenses/_form"=>1, "_form"=>1} to include "form".
Commits on Sep 24, 2015
@mcmire mcmire Provide example of RSpec +

* Many people have opened issues in the past fixing the RSpec examples
  in the documentation to use `` instead of `should`.

To satisfy the above:

* Clarify in the README that `should` is still acceptable syntax and
  that is what we are going to use in the README and documentation.

[ci skip]
@mcmire mcmire Update appraisal gemfiles 3c2fe12
Commits on Sep 25, 2015
@mcmire mcmire Mix into corresponding RSpec example groups

* Currently, our matchers are mixed into every example group under
* This creates a problem because some gems, such as
  active_model_serializers-matchers, provide matchers that are named
  the same as the ones that we provide.

To satisfy the above:

* Only mix matchers that correspond to a particular Rails module into
  the appropriate example group for that module. In detail:
    * Mix ActiveModel and ActiveRecord matchers into model example
    * Mix ActionController matchers into controller example groups.
@mcmire mcmire Add a new Routing module

* The `route` matcher can not only be used within controller example
  groups but also routing example groups.
* Now that we are mixing matchers into specific example groups, `route`
  is no longer available in routing example groups.

To satisfy the above:

* Create a new module that contains a `route` method and returns a new
  instance of RouteMatcher. (RouteMatcher still lives in the
  ActionController namespace.)
* Mix this module into routing example groups when the gem configuration
  block is run.
@mcmire mcmire Rewrite the tests for ComparisonMatcher

* The tests for ComparisonMatcher don't actually test
  ComparisonMatcher -- they test the comparison qualifiers for
  NumericalityMatcher. Not only is this misleading, but it also creates
  a problem as `validate_numericality_of` is no longer available in any
  example group, but only ones that have been specially tagged.

To satisfy the above:

* Ensure that the tests build an instance of ComparisonMatcher and test
  against that.
* Fix style issues with the tests.
* Additionally, add a #description method to ComparisonMatcher while
  we're at it.
@mcmire mcmire Bump Appraisal to 2.1.0

* At some point a while back, Appraisal introduced a bug fix that made
  it possible to run `rspec` through `appraisal` and pass the `-e`
  option to target certain tests. This makes life much easier.
* It's been a while since we've upgraded Appraisal anyway.
@mcmire mcmire Rewrite tests for ActionController::RouteMatcher

* We recently added Routing::RouteMatcher; the tests for those were
  roughly copied from those for ActionController::RouteMatcher but were
  rewritten, so we want to make the tests consistent between the two.
* The names of the existing tests weren't descriptive enough.
* The tests involving globs inside of routes should have been run
  twice -- once in the case that controller and action are separate
  options, another in the case that controller and action are specified
@mcmire mcmire Update NEWS
[ci skip]
Commits on Sep 27, 2015
@mcmire mcmire Tighten CouldNotSetAttributeError restriction

* Previously, `allow_value` would raise a CouldNotSetAttributeError
  if the value being set didn't match the value the attribute had after
  being set, but only if the attribute was being changed from nil to
  non-nil or non-nil to nil.
* It turns out it doesn't matter which value you're trying to set the
  attribute to -- if the attribute rejects that change it's confusing
  either way. (In fact, I was recently bit by a case in which I was
  trying to validate numericality of an attribute, where the writer
  method for that attribute was overridden to ensure that the attribute
  always stored a number and never contained non-number characters.
  This ended up making the numericality validation useless, of
  course -- but it caused confusion because the test acted in a way
  I didn't expect.)

To satisfy the above:

* `allow_value` now raises a CouldNotSetAttributeError if the attribute
  rejects the value being set in *any* way.
* However, add a `ignoring_interference_by_writer` qualifier so that
  it is possible to manually override this behavior.
* Fix tests that are failing now because of this new change:
  * Fix tests for allow_value matcher
  * Fix tests for numericality matcher
  * Remove tests for numericality matcher + integer column
    * An integer column will typecast any non-integer value to an
    * Because of the typecasting, our tests for the numericality matcher
      against an integer column don't quite work, because we can't
      really test what happens when the attribute is set to a
      non-integer value. Now that `allow_value` is more strict, we're
      getting a CouldNotSetAttributeError when attempting to do so.
    * The tests mentioned were originally added to ensure that we are
      handling RangeErrors that ActiveRecord used to emit. This doesn't
      happen anymore, so the tests aren't necessary anymore either.
  * Fix tests for acceptance matcher
  * Fix tests for absence matcher
@mcmire mcmire Update NEWS
[ci skip]
Commits on Sep 29, 2015
@mcmire mcmire Fix #permit so #on works and is properly tested

* When using #permit with the #on qualifier to assert that #permit was
  called on a subset of the params hash (selected using #require), the
  matcher would fail. The matcher didn't properly detect that #permit
  was called on the slice -- it thought it was called on the parent
  params object.
* It turns out this was a bug in Doublespeak. When #require is called,
  we take the subset of the params, which is also an
  ActionController::Parameters object like params, and we stub #permit
  on it at runtime. Unfortunately the Double object created here was
  never activated, so when #permit was called, this Double wasn't the
  one run. Instead, the Double on #permit within the
  ActionController::Parameters class (which is stubbed at the beginning)
  was the one that was run, and it's this object that recorded the call
  on #permit incorrectly.
* This bug slipped through because it turns out when #on was added it
  wasn't tested very well.

To satisfy the above:

* Modify Doublespeak so that when it is in activated mode, whenever
  new doubles are created, activate them immediately.
* Fix all of the tests for #permit around operating on a slice of the
  params hash so that they use the #on qualifier.
Commits on Sep 30, 2015
@mcmire mcmire Add missing test for permit matcher
We don't have a test to confirm that if you are using #require in your
controller twice to select the same slice of the params hash, but then
you are calling #permit on each slice with different keys, then the
permit matcher can cope with this.
@mcmire mcmire Fix formatting issues with #permit failure messages
This commit simply fixes the failure messages for #permit so that
instead of looking like this:

    Expected POST #create to restrict parameters  for :personto :name, :age, :city, and :country, but ...

they look like this:

    Expected POST #create to restrict parameters on :person to :name, :age, :city, and :country, but ...

Also, flesh out more of the tests for the failure messages.
@mcmire mcmire Add debugging helps to Doublespeak

* When debugging #permit it's been helpful to loop through all of the
  doubles that Doublespeak has registered and spit out all of the calls
  on those doubles (specifically which arguments they've received).
* It's also been helpful to know where the methods the doubles represent
  have been called.

To satisfy the above:

* Add #calls_by_method_name to DoubleCollection
* Add #caller to MethodCall
@mcmire mcmire Improve architecture for permit matcher

* There were architectural issues with how the permit matcher kept track
  of params instances on which doubles had been placed. Previously we
  were starting off by taking the ActionController::Parameters class and
  stubbing the #permit and #require instance method on it -- in other
  words, we were stubbing #require for all instances of
  ActionController::Parameters -- then we would stub #permit on a
  particular instance of ActionController::Parameters that #require
  returned. What this means is that if for some reason the #permit stub
  on an individual instance isn't working properly, then the #permit
  stub on ActionController::Parameters will respond to the invocation.
  This is exactly what happened for the issue we recently fixed --
  if the stubbing were done a different way we wouldn't have run into
  that issue.
* Also, there's no reason to have both ParametersDoubles and
  SliceOfParametersDoubles classes around. While it's nice that we have
  a simpler option to use if we don't need the more complex one, we
  actually don't need a distinction here, and we can afford one class
  that does both.

To satisfy the above:

* When stubbing #permit or #require, always do so on an instance of
  ActionController::Parameters and not the whole class. This way we know
  exactly which methods are being doubled and it's easier to debug things
  in the future.
* This means that we now stub and then
  place stubs on the returned instance.
* Refactor ParametersDoubles and SliceOfParametersDoubles: combine them
  into a ParametersDoubleRegistry class, but extract the code that stubs into
  a CompositeParametersDoubleRegistry class.
* Since this broke one of the tests, modify DoubleCollection so that a
  method cannot be doubled more than once -- if the method is already
  doubled then `register_stub` or `register_proxy` does nothing and
  returns the original Double.
@mcmire mcmire Update NEWS
[ci skip]
@mcmire mcmire Use doc formatter when running Doublespeak tests 46bb5d8
@maurogeorge maurogeorge Fix the set_flash matcher to accept a symbol as a param
This is a regression bug fix, on the previous version the matcher
accepts a string or a symbol as a param.

This commit brings back this behavior.
@mcmire mcmire Remove commented-out code from FlashStore a6e2cda
@mcmire mcmire Fix presence matcher to work with serialized attrs

* Given a model with an attribute that typecasts its incoming values to
  a collection type such as array or hash (and assuming that the default
  value is empty), the presence matcher failed to run successfully.
  Because we assert that the attribute `should_not allow_value(nil)`,
  and since nil is being typecast to an empty array or hash,
  `allow_value` was raising CouldNotSetAttributeError.

To satisfy the above:

* Rescue CouldNotSetAttributeError; if it occurs, assert that the actual
  value of the attribute is blank instead of the given value.
@mcmire mcmire Update YARD CSS to hide info on method aliases

* If a method has an alias, then YARD will append "(aliased to #foo)"
  inside of the header for the method. This doesn't look that great with
  the current layout, and we can easily mention the alias within the
  description for the method in question.

To satisfy the above:

* Hide this section of the header if it appears.

[ci skip]
@mcmire mcmire Update docs for #allow_value
* Remove explanation of and de-emphasize difference between `should
  allow_value` and `should_not allow_value`; reword.
* Add docs for `ignoring_inteference_by_writer` and background on when
  one would get a CouldNotSetAttributeError.

[ci skip]
@mcmire mcmire Refer to Minitest in docs over Test::Unit
Minitest has been used instead of Test::Unit for quite some time now,
let's get with the times.

[ci skip]
@mcmire mcmire Hide Routing module in docs
[ci skip]
@mcmire mcmire Fix header in docs
[ci skip]
@mcmire mcmire Tweak README
[ci skip]
@mcmire mcmire Update NEWS
[ci skip]
Commits on Oct 01, 2015
@mcmire mcmire Update rspec-core and rspec-expectations to latest versions 499081b
@mcmire mcmire Make independent matchers really independent

* When `delegate_method` was modified a while back to add Doublespeak
  and use MatcherContext, Shoulda::Matchers::Independent became unable
  to be required independently.

To satisfy the above:

* Require Doublespeak and MatcherContext within
* Add an acceptance test to ensure that Independent stays independent.

Secondary-Author: jc00ke <>
@mcmire mcmire Update NEWS
[ci skip]
@mcmire mcmire Update NEWS
[ci skip]
@mcmire mcmire Bump version to 3.0.0 :tada: 2a04930
@mcmire mcmire Remove 2.8.0-specific verbiage from README
[ci skip]
Commits on Oct 04, 2015
@mcmire mcmire Fix NEWS
[ci skip]
@mcmire mcmire Fix inclusion matcher w/ date & datetime attrs

* The inclusion matcher (when used with the `in_array` qualifier) makes
  the assertion that when the attribute is set to a value that is
  outside the given array, the record in question is invalid. The issue
  is that when used with a date or datetime attribute, the arbitrary
  value the matcher chose was a string. This was getting typecast and so
  the matcher was throwing a CouldNotSetAttributeError.

To satisfy the above:

* If the column is a date, use a Date for the arbitrary value
* If the column is a datetime, use a DateTime for the arbitrary value
* If the column is a time, use a Time for the arbitrary value
Commits on Oct 05, 2015
@mcmire mcmire inclusion: Test with timestamp columns too 73e3995
@mcmire mcmire Suggest using semver when adding gem to Gemfile

* People who didn't specify some kind of version qualifier when they
  added shoulda-matchers to their Gemfile and accidentally upgraded to
  3.0 are now getting burned. We don't want this to happen for new
  users of the gem when 4.0 comes out.

To satisfy the above:

* Modify the installation instructions in the README to suggest people
  use the squiggly operator to lock the gem down to 3.x.

[ci skip]
Commits on Oct 08, 2015
@mcmire mcmire Upgrade rspec 07fe5eb
@mcmire mcmire Extract a common spec helper
In order to write tests for the `word_wrap` method we have, we need a
spec helper that we can require. We don't need anything fancy. The
doublespeak_spec_helper is doing most of what we want except for the
Doublespeak require.
@albertyw albertyw Fix unclear spec context message 2f6c143
Commits on Oct 09, 2015
@mcmire mcmire Improve the word_wrap utility method
We use the word_wrap method right now to reformat warning messages so
that they fit within a 72-character space. We'd like to use this for
error messages too, but we want the word_wrap method to be smart when
reformatting bulleted or numbered lists, and also to ignore code blocks.
@albertyw albertyw Fix checking case sensitivity when value is case insensitive ada9bd3
@mcmire mcmire Make improvements to the YARD layout
* Adjust padding/margin around and inside of blockquotes
* Use ems for p margin
* Since we will be adding a custom file whose title is camel-case,
  make two changes to the header:
  * Drop "File:" in the header for files
  * Change styles for header and search to use standard case instead
    of all caps, and drop letter spacing
* Make footer smaller and more human readable
@mcmire mcmire Extend list of files to watch to regen docs
Now updating these files will regenerate the docs:

* .yardopts
* docs/
* .rb, .js, .css, and .erb files inside of doc_config/
@mcmire mcmire Add docs for NonCaseSwappableValueError 80407e6
@mcmire mcmire Update NEWS to add NonCaseSwappableValueError 1a85124
@biow0lf biow0lf Always use Rack::Utils::SYMBOL_TO_STATUS_CODE 4b72989
@biow0lf biow0lf Fix typo 7db1013
@mcmire mcmire Update CouldNotSetAttributeError message to be more useful ba953f8
@mcmire mcmire Fix numericality matcher w/ numeric columns
Fix the matcher so it still raises a CouldNotSetAttributeError against a
numeric column, but only if the matcher has not been qualified at all.
When the matcher is qualified with anything else, then it's okay to use
a numeric column, as long as the matcher no longer asserts that the
record disallows a non-numeric value.
@mcmire mcmire Tweak message for IneffectiveTestError 369e9d4
Commits on Oct 13, 2015
@georgemillo georgemillo English fix
@georgemillo georgemillo Reduce line length to <= 80
Commits on Oct 23, 2015
@reacuna reacuna Do not raise CouldNotSetAttributeError on decimal columns a0f1221
@mcmire mcmire Update NEWS
[ci skip]
@mcmire mcmire Bump version to 3.0.1
[ci skip]
Commits on Oct 28, 2015
@maclover7 maclover7 Test on latest point releases of Ruby
[fixes #813]
@gmmcal gmmcal Update on validates_uniqueness_of documentation example
[ci skip]
@olimart olimart Fix anchor link to Configuration section
Commits on Oct 30, 2015
@seanpdoyle seanpdoyle Fix `#configuration` links in README
Linking to `#Configuration`  wasn't scrolling the browser to the appropriate anchor in the README
@mcmire mcmire Improve contributing workflow
* Add missing steps to CONTRIBUTING and reorganize it a bit.
* `bundle exec rake` no longer runs all tests in all appraisals, only
  the tests in the latest appraisal.
* Add a `.ruby-version` file so people don't have to figure out which
  version of Ruby to install.

[ci skip]
Commits on Nov 06, 2015
@mcmire mcmire Document availability of matchers
Add instructions especially for people who are using ActiveModel or
ActiveRecord outside of Rails and want to use model matchers to test an
arbitrary model.

[ci skip]
Commits on Nov 20, 2015
@aripollak aripollak Fix permit docs for shoulda-context
`should` is not a valid method inside a `should` block, so we have to use
`assert_accepts` instead. This lets us use any variables from the setup block,
as opposed to a bare `should` which requires us to know all parameters
up front.
@aripollak aripollak Remove unused methods 8e68d99