1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

18 commits

Author SHA1 Message Date
Xavier Noria
a731125f12 applies new string literal convention in activesupport/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:10:53 +02:00
Genadi Samokovarov
16f24cd10f Introduce assert_changes and assert_no_changes
Those are assertions that I really do miss from the standard
`ActiveSupport::TestCase`. Think of those as a more general version of
`assert_difference` and `assert_no_difference` (those can be implemented
by assert_changes, should this change be accepted).

Why do we need those? They are useful when you want to check a
side-effect of an operation. `assert_difference` do cover a really
common case, but we `assert_changes` gives us more control. Having a
global error flag? You can test it easily with `assert_changes`. In
fact, you can be really specific about the initial state and the
terminal one.

```ruby
error = Error.new(:bad)
assert_changes -> { Error.current }, from: nil, to: error do
  expected_bad_operation
end
```

`assert_changes` follows `assert_difference` and a string can be given
for evaluation as well.

```ruby
error = Error.new(:bad)
assert_changes 'Error.current', from: nil, to: error do
  expected_bad_operation
end
```

Check out the test cases if you wanna see more examples.

🍻
2016-07-17 12:58:57 +03:00
Lucas Mazza
564b162015 Make assert_difference return the result of the yielded block.
With this we can perform new assertions on the returned value without having
to cache it with an outer variable or wrapping all subsequent assertions inside
the `assert_difference` block.

Before:

```
post = nil
assert_difference -> { Post.count }, 1 do
  Post.create
end

assert_predicate post, :persisted?
```

Now:

```
post = assert_difference -> { Post.count } do
  Post.create
end

assert_predicate post, :persisted?
```
2015-09-24 14:17:49 -03:00
Guo Xiang Tan
5a973b314b Remove alias for i_suck_and_my_tests_are_order_dependent. 2015-03-24 00:27:53 +08:00
Rafael Mendonça França
5f777e4b5e Change the default test order from :sorted to :random 2015-01-04 11:58:41 -03:00
Godfrey Chan
2b41343c34 Default to sorting user's test cases for now
Goals:

1. Default to :random for newly generated applications
2. Default to :sorted for existing applications with a warning
3. Only show the warning once
4. Only show the warning if the app actually uses AS::TestCase

Fixes #16769
2014-09-08 05:32:16 -07:00
Zachary Scott
5efcf3800e Move as/test_test to as/test_case_test 2014-08-19 23:40:42 -07:00
kennyj
6c2cbc6fff Remove active_support/testing/pending.rb was deprecated. 2013-06-01 21:23:19 +09:00
Ryan Davis
3073c53198 Updates to make rails 4 happy with minitest 5:
+ Namespace changes, overhaul of runners.
+ Internal ivar name changes
- Removed a logger globally applied to tests that spew everywhere?!?
+ Override Minitest#__run to sort tests by name.
+ Reworked testing isolation to work with the new cleaner architecture.
- Removed a bunch of tests that just test minitest straight up. I think these changes were all merged to minitest 4 a long time ago.
- Minor report output differences.
2013-05-06 17:38:45 -07:00
Carlos Antonio da Silva
da47960893 Fix failures in AS with minitest 4.7.4 2013-05-01 23:21:08 -03:00
Carlos Antonio da Silva
92da512125 Properly deprecate #pending from AS::TestCase
Check https://github.com/rails/rails/pull/4575#issuecomment-5765575.
2012-11-18 21:34:00 -02:00
Rafael Mendonça França
ae6d2efd84 Make the tests pass with minitest 4.2 2012-11-05 15:12:09 -02:00
James Mead
b057fab638 Exceptions like Interrupt should not be rescued.
Neither Test::Unit nor MiniTest rescue exceptions like Interrupt or
NoMemoryError, but ActiveSupport::Testing::SetupAndTeardown#run which
overrides MiniTest::Unit::TestCase#run rescues them.

Rescuing an Interrupt exception is annoying, because it means when you
are running a lot of tests e.g. when running one of the rake test tasks,
you cannot break out using ctrl-C.

Rescuing exceptions like NoMemoryError is foolish, because the most
sensible thing to happen is for the process to terminate as soon as
possible.

This solution probably needs some finessing e.g. I'm not clear whether
the assumption is that only MiniTest is supported. Also early versions
of MiniTest did not have this behaviour. However, hopefully it's a
start.

Integrating with Test::Unit & MiniTest has always been a pain. It would
be great if both of them provided sensible extension points for the kind
of things that both Rails and Mocha want to do.
2012-05-28 22:44:28 +01:00
Aaron Patterson
f65559fcc2 make sure the test case name is nil 2012-01-06 15:17:08 -08:00
Rafael Mendonça França
b2fca9533e No need to check if MiniTest::Assertions is defined 2012-01-06 13:31:39 -03:00
Aaron Patterson
e477fc1147 fixing test case test on 1.9.3dev 2011-03-01 10:14:09 -08:00
Aaron Patterson
b7c49cedba calling correct method on minitest for test name when teardown callback fails 2010-10-04 09:34:34 -07:00
Aaron Patterson
ccf228b027 [#5406 state:resolved] calling the correct method on minitest to obtain the test name 2010-10-04 09:33:35 -07:00