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.
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.
* 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 set_session.to('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
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.
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.
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
* Change 'spec' Rake task to 'spec:unit'
* Require unit_spec_helper.rb in unit tests, not spec_helper.rb
* Re-namespace files in spec/support/unit under UnitTests
* Files in spec/support/unit/helpers no longer automatically add
themselves to RSpec - this happens in unit_spec_helper.rb
* Extract RecordWithDifferentErrorAttributeBuilder and
RecordValidatingConfirmationBuilder to separate files
* Move spec/shoulda to spec/unit_tests/shoulda
* Move spec/support/*.rb to spec/support/unit_tests/{helpers,matchers}
* Move spec_helper.rb to unit_spec_helper.rb