Commit Graph

31 Commits

Author SHA1 Message Date
Kapil Sachdev ee1008de7a fix(rubocop): Fix Layout related offenses [ci skip]
- Layout/EmptyLines
- Layout/EmptyLineAfterGuardClause
- Layout/TrailingEmptyLines
- Layout/EmptyLinesAroundBlockBody
- Layout/EmptyLinesAroundModuleBody
- Layout/EmptyLineAfterMagicComment
- Layout/SpaceInsidePercentLiteralDelimiters
- Layout/SpaceAroundEqualsInParameterDefault
- Layout/SpaceInsideArrayLiteralBrackets
- Layout/LeadingCommentSpace
- Layout/SpaceBeforeComment
- Layout/SpaceAroundOperators
- Layout/SpaceInsideRangeLiteral
- Layout/SpaceInsideReferenceBrackets
- Layout/SpaceInLambdaLiteral
- Layout/SpaceAfterComma
- Layout/SpaceInsideHashLiteralBraces
- Layout/TrailingWhitespace
- Layout/ArgumentAlignment
- Layout/HashAlignment
- Layout/DotPosition
- Layout/IndentationWidth
- Layout/EndAlignment
- Layout/MultilineOperationIndentation
- Layout/IndentationConsistency
- Layout/ClosingHeredocIndentation
- Layout/MultilineMethodCallBrace- Layout
- Layout/ClosingParenthesisIndentation
2020-11-03 10:05:25 -07:00
Kapil Sachdev 4d7cedc5af fix(rubocop): Use __dir__ for Style/ExpandPathArguments [ci skip] 2020-11-03 10:05:25 -07:00
Kapil Sachdev 97722f67cb fix(rubocop): Satisfy Style/StringLiterals with single_quotes [ci skip] 2020-11-03 10:05:25 -07:00
Gui Vieira 0e6db542be
Remove code for unsupported versions (#1270) 2020-01-01 19:10:35 -08:00
Elliot Winkler fcf4a6df92 Only turn on VERBOSE after requiring shoulda-matchers
[ci skip]
2019-03-20 22:44:06 -07:00
Elliot Winkler da4e6ddd06 Add failing tests for issue 1146 2019-01-29 23:33:06 -07:00
Elliot Winkler ebe60449ee Fix inclusion to correctly disallow outside values
The inclusion matcher, when qualified with `in_array`, was using
AllowValueMatcher to check that values outside the array were disallowed
by the model (and then inverting its result). However, it should have
been using DisallowValueMatcher all this time. This commit fixes that.

Without this fix, the following error is raised when using the inclusion
matcher against a model which does not have the proper inclusion
validation on it:

    undefined method `attribute_setter' for nil:NilClass

This happens because the inclusion matcher is a complex matcher, i.e.,
it runs a series of submatchers internally and the result of those
submatchers contributes to whether or not the matcher matches. If one of
those submatchers fails, the inclusion matcher immediately fails and
spits out the failure message associated with that submatcher.

However, there is a fundamental difference between AllowValueMatcher and
DisallowValueMatcher as it relates to how they function:

* AllowValueMatcher sets an attribute to a value on a record and expects
  the record not to fail validation.
* DisallowValueMatcher sets an attribute to a value on a record, but
  expects the record *to* fail validation.

The issue in this case is that, because AllowValueMatcher was used
instead of DisallowValueMatcher, the inclusion matcher thought that the
AllowValueMatcher failed, when in fact it passed (this result was just
inverted). So it tried to generate a failure message for a matcher that
didn't fail in the first place. By using DisallowValueMatcher, we set
the proper expectations.
2018-09-15 13:43:30 -03:00
Elliot Winkler d8681fa721 Improve failure messages for define_enum_for
If a subtest fails, explain why. We're going to be adding another
subtest later, and so without this extra information, users will most
definitely be confused.
2018-01-28 00:47:44 -06:00
Murtaza Gulamali ce9624b3c5 Scope request parameters according to Rails version 2017-09-17 17:46:06 -05:00
Elliot Winkler 98ef8f67da Don't require ActiveResource tests under Rails 5 2017-09-17 17:01:50 -05:00
Elliot Winkler 335971a87c Add ValidationMatcherScenario for use in tests
Also add a helper method, `build_scenario_for_validation_matcher`, to
all unit tests.

Our plan is to slowly transition all of the tests to use this helper
method, and that we we can get rid of the umpteen different ways we are
building records across all of the tests.
2016-01-05 00:58:16 -07:00
Elliot Winkler d902b72d15 Add 'it supports' as an alias for 'it behaves like'
Oftentimes our shared example groups represent tests for qualifiers.
It's more natural to say "it supports ignoring_interference_by_writer"
instead of "it behaves like it supports
ignoring_interference_by_writer".
2015-12-30 22:04:06 -05:00
Elliot Winkler 97a627c273 Upgrade RSpec to v3.4
v3.3 introduced a new feature: the ability to re-run failed specs. v3.4
contains some other nifty features, such as code highlighting and
compound failure messages.
2015-12-30 21:58:31 -05:00
Elliot Winkler 3ee734bb7e Speed up running unit tests with Zeus
This is an effort to vastly decrease the time it takes to run a single
unit test file and therefore increase productivity and happiness for
people working on this project.

If you want to run a unit test file, now you can use `zeus rspec`
instead of `rspec` -- assuming you run `zeus start` first -- and it will
run a LOT faster.

Because test files tend to have long file paths, you can even use a
shorter version of those paths. So instead of saying:

    zeus rspec spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb

you can say:

    zeus rspec active_record/validate_uniqueness_of_matcher_spec.rb
2015-12-13 20:22:21 -07:00
Elliot Winkler 6cc7fd8ca2 Remove warnings shown when running tests
* For some reason, ActiveRecord was printing a warning saying that
  "active_record/base" was already being loaded and there was a possible
  circular dependency. We fix this by explicitly requiring
  "active_record/base" before `$VERBOSE` is set to true.
* We were getting warnings when re-defining Kernel.capture,
  Kernel.silence_stream and Kernel.silence_stderr, so undefine them
  first.
2015-12-13 20:22:21 -07:00
Elliot Winkler 878e9582e1 Extract a common spec helper
In order to write tests for the `word_wrap` method we have, we need a
spec helper that we can require. We don't need anything fancy. The
doublespeak_spec_helper is doing most of what we want except for the
Doublespeak require.
2015-10-07 23:32:51 -06:00
Mauro George c14f344e3e Run formatter documentation when running a single file
Today if we run a single file or spec like `callback_matcher_spec.rb` or
`callback_matcher_spec.rb:12` the formatter is the default dot.

With this config when we run a single file or spec the formatter is the
documentation and when we run the suite the formatter is the default dot.
2015-06-13 10:37:31 -03:00
Elliot Winkler 72f60fae94 Add support for Postgres
When running tests, you can now switch between running them against a
SQLite or PostgreSQL database. This is accomplished by modifying the
unit and acceptance tests so that when they generate and load the test
Rails application, database.yml is replaced with content that will
configure the database appropriately.
2015-02-12 16:01:00 -07:00
Elliot Winkler 190007155e Remove auto-detection of Rails / test framework 2015-02-09 10:52:51 -07:00
Elliot Winkler a4045a1f9b Remove Rails 3.x, Ruby 1.9.2, Ruby 1.9.3
Ruby 1.9.3 will be end-of-lifed on February 23, 2015. We might as well
remove support for it now.
2015-02-09 10:52:22 -07:00
Elliot Winkler 9a903f523c Raise an error if no Appraisal is specified
If you attempt to run tests without specifying an Appraisal, then you
will be going off of the main Gemfile. The Gemfile is not guaranteed to
contain all of the dependencies necessary to run tests, so it is very
likely that you'll get an obscure error somewhere. Instead of letting
this happen, raise a specific error.
2015-02-05 18:03:32 -07:00
Elliot Winkler 9ba21381d7 Handle RangeErrors emitted now in ActiveRecord 4.2
In Rails 4.2, ActiveRecord was changed such that if you attempt to set
an attribute to a value and that value is outside the range of the
column, then it will raise a RangeError. For instance, an integer column
with a limit of 2 (i.e. a smallint) only accepts values between -32768
and +32767.

This means that if you try to do any of these three things, a RangeError
could be raised:

* Use validate_numericality_of along with any of the comparison
  submatchers and a value that sits on either side of the boundary.
* Use allow_value with a value that sits outside the range.
* Use validates_inclusion_of against an integer column. (Here we attempt
  to set that column to a non-integer value to verify that the attribute
  does not allow said value. That value is really a string version of a
  large number, so if the column does not take large numbers then the
  matcher could blow up.)

Ancillary changes in this commit:

* Remove ValidationMessageFinder and ExceptionMessageFinder in favor of
  Validator, StrictValidator, and ValidatorWithCapturedRangeError.
* The allow_value matcher now uses an instance of Validator under the
  hood. StrictValidator and/or ValidatorWithCapturedRangeError may be
  mixed into the Validator object as needed.
2015-01-22 21:05:09 -07:00
Elliot Winkler 7dfbc5e0c2 Ensure that ActiveSupport warnings are being printed during tests 2014-12-25 00:45:06 -05:00
Elliot Winkler fab4f02da3 Fix AC matcher tests for Rails 4.2
Modify helper methods provided by ControllerBuilder so that we use as
much of rspec-rails's controller example group capabilities as possible.
All of this can still be improved but this is a good start for now.
2014-12-25 00:45:04 -05:00
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 3a76f9389f Convert from Mocha to RSpec Mocks 2014-11-19 16:43:32 -07:00
Elliot Winkler 1a5bbfa34c Run tests in a random order 2014-11-06 14:16:51 -07:00
Elliot Winkler 3fb4cdb3b7 Add new RSpec acceptance tests to replace Cucumber 2014-11-05 09:53:33 -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