Commit Graph

23 Commits

Author SHA1 Message Date
Elliot Winkler a9ab35117b 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.
2014-12-25 00:44:54 -05:00
Elliot Winkler d86fe2d1c0 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.
2014-12-25 00:44:53 -05:00
Elliot Winkler 76c2f6630c Move test for validate_length_of to the right place 2014-12-16 20:14:53 -07:00
Elliot Winkler 502a2d3441 Remove warning when running tests 2014-12-15 23:05:52 -07:00
Aditya Kapoor 18201d4f95 Add with_prefix to delegate_method
Secondary author: Elliot Winkler <elliot.winkler@gmail.com>
2014-12-15 22:38:27 -07:00
Elliot Winkler f82d4eeedd Improve certain names of tests for delegate_method 2014-12-14 23:35:30 -07:00
Elliot Winkler 1694c7bcb9 Rename vars in delegate_method to match terminology in docs 2014-12-13 19:08:25 -05:00
Elliot Winkler cf76d747ee Move uniqueness validation to ActiveRecord module 2014-12-13 17:53:16 -05:00
Elliot Winkler b84ec8cc16 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 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
2014-11-21 14:27:44 -07:00
Elliot Winkler 5cfe0403e6 Reorganize set_session tests 2014-11-21 14:24:34 -07:00
Elliot Winkler c8fb8022b1 Deprecate set_the_flash in favor of set_flash 2014-11-21 14:24:00 -07:00
Elliot Winkler 0eb10915db set_the_flash => set_flash 2014-11-21 11:36:27 -07:00
Sean Doyle 0e2e9c4519 Add `validate_uniqueness_of_(:foo).allow_blank`
This re-applies fcbc16e7d6.
2014-11-20 12:28:16 -07:00
Elliot Winkler 47a0392b77 Ensure route matcher works with namespaced controllers 2014-11-19 16:44:10 -07:00
Elliot Winkler abb087e6bb 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.
2014-11-19 16:44:10 -07:00
Elliot Winkler a1dbca39f0 Refactor route specs 2014-11-19 16:44:10 -07:00
Elliot Winkler 3a76f9389f Convert from Mocha to RSpec Mocks 2014-11-19 16:43:32 -07:00
Elliot Winkler 5f8c3235d0 Fix validate_inclusion_of + with_message
It did not fail if the given message did not match the message on the
validation itself.
2014-11-18 21:03:06 +08:00
Elliot Winkler 2162965445 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.
2014-11-06 14:16:54 -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 d976118b9a Rename {ensure => validate}_length_of 2014-11-05 11:38:58 -07:00
Elliot Winkler f922613386 Reorganize unit tests, part II
* 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
2014-11-05 09:53:20 -07:00
Elliot Winkler bbdf8a807e Reorganize unit tests, part I
* 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
2014-11-04 14:43:59 -07:00