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.
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>]...
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.
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
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`.