1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00
Commit graph

15 commits

Author SHA1 Message Date
Elliot Winkler
8cf449b4ca Add a new Routing module
Why:

* 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.
2015-09-25 17:45:33 -06:00
Elliot Winkler
3e2c4e11ae Omit newest private modules from docs
[ci skip]
2015-03-01 01:20:45 -07:00
Elliot Winkler
190007155e Remove auto-detection of Rails / test framework 2015-02-09 10:52:51 -07:00
Elliot Winkler
72e2b3411e Fix define_class/model to support namespaces
You can now say `define_class('Models::User')` and it will define a User
class inside of the Models module.

Similarly, you can also say `define_model('Models::User')` and it will
set the table name of the model to `models_users` instead of just
`users`.
2014-10-08 23:22:50 -06:00
Elliot Winkler
c683aed2f0 Fix delegate_method when used with shoulda-context
When specifying a custom subject, a straightforward usage of
`delegate_method`, such as the following

    class UserPresenter
      delegate :id, to: :user

      attr_reader :user

      def initialize(user)
        @user = user
      end
    end

    class UserPresenterTest < ActiveSupport::TestCase
      subject { UserPresenter.new(User.new) }
      should delegate_method(:id).to(:user)
    end

would error with something like:

    ArgumentError: wrong number of arguments (0 for 1)

This happens because the `should` method in shoulda-context asks the
DelegateMethodMatcher object for its description so that it can use it
to give the test a name and create a method that Test::Unit can run.
Now, the matcher's description needs a subject in order to determine
whether a class or an instance is being tested here -- if a class is
being tested the description will be "should delegate #id to \#user
object", if a class then "should delegate .id to .user object".
Unfortunately the matcher doesn't know what the subject is before
its #description method is called -- it only knows about this when it
gets evaluated.

Within the matcher we do have access to the current context class, so we
could read the subject block off of it and evaluate it. However, in
order to properly do this we also need access to the instance of the
test itself, which we do not have until the matcher is evaluated (by
which point it's too late).

Since there's really no way to solve this problem apart from rewriting a
lot of shoulda-context, and since often times your subject is an
instance and not a class, just assume it's an instance in this case.
2014-10-08 01:05:37 -06:00
Elliot Winkler
dfebd81af0 Add a small stubbing library
This provides a robust solution for temporarily stubbing (and
unstubbing) methods. It will be internally by the strong parameters and
delegation matchers.
2014-04-22 09:37:27 -05:00
Elliot Winkler
cd9594603e Remove warning under Minitest 5
Under Minitest 5 (or a Rails 4.1 project), you will get a warning

    MiniTest::Unit::TestCase is now Minitest::Test.

when you attempt to run tests. This is because shoulda-matchers requires
'test/unit/testcase', even if Test::Unit is not being used.

It is not a good idea for shoulda-matchers to require *anything* that
the user may not be using, whether it's Test::Unit or RSpec. We should
assume that by the time shoulda-matchers is required, the user has
already required all of whatever test framework they are using, not none
or even some of that framework.
2014-04-04 15:07:28 -06:00
Elliot Winkler
5b44edf8b3 Handle ensure_inclusion_of for boolean columns
Currently, using `ensure_inclusion_of` against a boolean column doesn't
work. We can assert that the column allows boolean values, but what
about values that should be rejected? Well, it depends on what you give
to `ensure_inclusion_of`. Here's how it works now:

* `ensure_inclusion_of(:attr).in_array([true])` asserts that false is
  rejected
* `ensure_inclusion_of(:attr).in_array([false])` asserts that true is
  rejected
* `ensure_inclusion_of(:attr).in_array([true, false])` does not assert
  that anything is rejected, instead informing the developer how
  this sort of expectation is not fully testable (anything other than
  true, false, or nil will be converted to false).
* `ensure_inclusion_of(:attr).in_array([nil])`, when the column is
  nullable, does not assert that anything is rejected, either, also
  printing a warning
* `ensure_inclusion_of(:attr).in_array([nil])`, when the column is
  non-nullable, raises an error because this expectation is not testable
  in any way, as setting a boolean column to nil this way will get
  converted to false.
2014-02-17 15:40:18 -07:00
Derek Prior
c4927b73f2 Fix render_with_layout_matcher on Rails 4.
Rails 4 moved the layouts ivar from `@layouts` to `@_layouts`.

This change introduces what I have (for now) called the 'RailsShim'. The
idea is that this single class will house the rail version workarounds,
which can then be reused through the code. This paid off here because
both the spec and the implementation need access to the layouts ivar.
2013-08-16 15:32:08 -06:00
Mike Burns
f185e3d9d0 Mix RSpec with Test::Unit
An edge case occurs when mixing RSpec and Test::Unit tests and also
loading both the 'rspec-rails' gem and 'shoulda-matchers' gem from the
same Gemfile group, namely [:test, :development] . Work around this by
always inserting the shoulda matchers into Test::Unit, regardless of
whether RSpec is loaded.
2012-07-11 12:17:04 +02:00
Timothy Yen
404d1f4ee8 Added shoulda/matchers/assertion_error that assigns based on the current Ruby version. 2011-02-17 13:37:30 -05:00
Ryan McGeary
b39fba0bed Switched to allowing a more canonical require statement
require "shoulda/matchers"  # canonical

-vs-

    require "shoulda-matchers"  # still allowed

See comments of http://blog.segment7.net/2010/11/15/how-to-name-gems
2011-01-31 16:45:13 -05:00
Joe Ferris
02a9753d8b Added Rspec-detection and integration 2009-01-31 15:52:45 -05:00
Joe Ferris
f732ae64c7 Removed a reference to the Thoughtbot namespace in the Matchers module 2009-01-27 18:10:59 -05:00
Joe Ferris
ba0a96221d Changed matchers and added a lib/shoulda/matchers include so that matchers can be used outside shoulda 2009-01-27 18:01:28 -05:00