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

7 commits

Author SHA1 Message Date
Elliot Winkler
67d5189437 uniqueness: Extract code to gen dummy values
We need to use this in another part of the codebase: later, when we add
ignoring_interference_by_writer to all matchers, we will need a way of
overriding an attribute such that it produces another value that
invalidates the test. Some tests require us to generate dummy values.
2016-01-05 00:58:16 -07:00
Elliot Winkler
6b3253147a allow_value: Inspect values more clearly
Modify descriptions and failure messages for all matchers by way of
allow_value and put small angle brackets around inspected values. This
is to visually distinguish an inspected value from the rest of the text,
and is especially noticeable for complex values such as an array that
contains an object, particularly if the inspected version of the value
wraps onto another line. It's a little easier to see:

    When attempting to set :attr on Example to ‹[#<Child id:
    nil>]›...

rather than:

    When attempting to set :attr on Example to [#<Child id:
    nil>]...
2015-12-30 21:51:54 -05:00
Elliot Winkler
b4df99f50e Add a_or_an utility method
The purpose of this method is to add a word to a string which is
prepended by "a" or "an", depending on whether that word starts with a
vowel.
2015-12-13 20:22:21 -07:00
Elliot Winkler
f67183ea59 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.
2015-10-08 21:30:41 -06:00
Elliot Winkler
de111ea5e8 Improve output of fail_with_message matcher 2015-01-22 21:05:08 -07:00
Elliot Winkler
b4bf814b3b 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
  end

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

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') }
    end

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
this:

    describe Models::User do
      it { should have_many(:friends).class_name('Friend') }
    end
2014-11-06 14:15:00 -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