aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing
Commit message (Collapse)AuthorAgeFilesLines
* fffffff, Add code missing in 29f0fbdKasper Timm Hansen2016-09-251-2/+2
|
* Revise setting of run_with_rails_extension.Kasper Timm Hansen2016-09-251-7/+4
| | | | | | | | | | | | | | | | | | | | | | | | The Rails test runner supports three ways to run tests: directly, via rake, or ruby. When Running with Ruby ala `ruby -Itest test/models/post_test.rb` our test file would be evaluated first, requiring `test_helper` and then `active_support/testing/autorun` that would then require the test file (which it hadn't been before) thus reevaluating it. This caused exceptions if using Active Support's declarative syntax. Fix this by shifting around when we set the how we're run to closer mimick the require order. If we're running with `bin/rails test` the test command file is run first and we then set `run_with_rails_extension`, later we hit `active_support/testing/autorun` and do nothing — because we've been run elsewhere. If we at this point haven't set `run_with_rails_extension` we've been running with `ruby` this whole time and thus we set that. We should always trigger `Minitest.autorun` as it doesn't hurt to call it twice. Consolidate the two methods into a single one that better brings out the intent of why they're there.
* use `message` that specified in argument to error messageyuuji.yaginuma2016-08-311-1/+1
|
* use `inspect` for show `from` valueyuuji.yaginuma2016-08-291-1/+1
| | | | If `from` is nil, in order to avoid the blank is showed.
* Move custom assertion to its proper placeSantosh Wadghule2016-08-271-0/+11
| | | | | | | | ActiveSupport::Testing::Assertions. We have a separate module in which have defined Rails' own custom assertions. So it would be good to keep all custom Rails' assertions in one place i.e. in this module.
* Add three new rubocop rulesRafael Mendonça França2016-08-161-1/+1
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* code gardening: removes redundant selfsXavier Noria2016-08-081-1/+1
| | | | | | | | | A few have been left for aesthetic reasons, but have made a pass and removed most of them. Note that if the method `foo` returns an array, `foo << 1` is a regular push, nothing to do with assignments, so no self required.
* applies remaining conventions across the projectXavier Noria2016-08-061-1/+0
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-28/+28
|
* applies new string literal convention in activesupport/libXavier Noria2016-08-067-13/+13
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* systematic revision of =~ usage in ASXavier Noria2016-07-221-1/+2
| | | | | Where appropriate prefer the more concise Regexp#match?, String#include?, String#start_with?, and String#end_with?
* Introduce `assert_changes` and `assert_no_changes`Genadi Samokovarov2016-07-171-0/+89
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. :beers:
* `travel/travel_to` travel time helpers, now raise on nested calls,Vipul A M2016-07-021-8/+43
| | | | | | | | | | | | | | | | | | | | | | | | | as this can lead to confusing time stubbing. Instead of: travel_to 2.days.from_now do # 2 days from today travel_to 3.days.from_now do # 5 days from today end end preferred way to achieve above is: travel_to 2.days.from_now # 2 days from today travel_back travel_to 5.days.from_now # 5 days from today Closes #24690 Fixes #24689
* Create times in rails timezone not system timezone [ci skip]aarongray2016-06-211-3/+3
| | | | | | Time.new is a Ruby method that uses system timezone. Traveling in time using it is a recipe for confusion. Instead, Time.zone.local should be used since it uses the Rails timezone.
* Remove an unused require in ActiveSupport::TestCaseGenadi Samokovarov2016-06-131-2/+0
| | | | We used to have `assert_blank` and `assert_presence`. [ci skip]
* Remove `_run_class_setup`Jon Moss2016-06-101-11/+0
| | | | Should have been removed by 3073c531983de243219fb55be93fbcebfdd9c44e.
* Extract line filtering to Railties.Kasper Timm Hansen2016-01-091-54/+0
| | | | | | | | | | | | The line filter parsing added to ActiveSupport::TestCase is only half the story to enable line filtering. The other half, of adding the patterns to the options, is done in the Minitest plugin that Railties has. Thus it makes more sense to have the filter in Railties with the other half and all the line filtering tests. Move the filter and extend Active Support in an initializer, so that when users or `rails/all.rb` require `rails/test_unit/railtie` we can still filter by line.
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2015-10-311-1/+1
|\
| * Fixed wording in Assertion docs, changed ‘Assert’ -> ‘Asserts’Ronak Jangir2015-10-071-1/+1
| |
* | Fix bug where custom deprecators are not used.Brandon Dunne2015-10-141-8/+9
|/ | | | | | | | | | | | Add tests for ActiveSupport::Deprecation.deprecate_methods Modify ActiveSupport::Testing::Deprecation to allow a custom deprecator Leverage ActiveSupport::Testing::Deprecation assert_deprecated Update documentation for ActiveSupport::Deprecation.deprecate_methods Use cases: Using the default deprecator => "removed from Rails X.Y" Passing a custom deprecator in the options hash => "removed from MyGem next-release" Deprecating methods directly from custom deprecator => "removed from MyGem next-release"
* make sure exceptions are marshalable when returning test resultsAaron Patterson2015-09-301-1/+17
| | | | | this should fix the error where isolation tests raise an exception and we just get a marshal error
* Improve readability of docs by using code tag [ci skip]Prakash Laxkar2015-09-291-1/+1
|
* Make `assert_difference` return the result of the yielded block.Lucas Mazza2015-09-241-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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? ```
* Cleaned up generators tests using internal assertion helperRonak Jangir2015-08-201-2/+4
|
* Replacing lambda with proc getting argument error because of it.Ronak Jangir2015-08-171-1/+1
|
* Added helper methods to stub any instanceRonak Jangir2015-08-131-1/+5
|
* Add multiple expected calls to assert_called_with.Kasper Timm Hansen2015-07-101-1/+6
|
* Add method call assertions for internal use.Kasper Timm Hansen2015-07-081-0/+30
| | | | | Add `assert_called` and `assert_not_called` to boil down the boilerplate we need to write to assert methods are called certain number of times.
* inline test runner check into `as/testing/autorun.rb`.Yves Senn2015-06-111-1/+8
| | | | | This makes it possible to easily get the runner working with existing setups that rely on `active_support/testing/autorun.rb`.
* Merge pull request #19571 from kaspth/improve-runner-integrationYves Senn2015-06-081-0/+54
|\ | | | | | | Improve Test Runner's Minitest integration.
| * Improve test runner's Minitest integration.Kasper Timm Hansen2015-06-041-0/+54
| | | | | | | | | | | | | | | | | | | | | | This also adds free mix and matching of directories, files and lines filters. Like so: bin/rails test models/post_test.rb test/integration models/person_test.rb:26 You can also mix in a traditional Minitest filter: bin/rails test test/integration -n /check_it_out/
* | A few documentation tweaks [ci skip]Robin Dupret2015-06-071-1/+1
|/ | | | [Robin Dupret & Shunsuke Aida]
* Remove `assigns` and `assert_template`.Guo Xiang Tan2015-05-301-1/+1
|
* use keyword arguments in HTTP request methods of assert_difference example ↵yuuji.yaginuma2015-05-241-9/+9
| | | | [ci skip]
* MRI compatible code for ActiveSupport::Testing::Isolation::SubprocessAlexey Gaziev2015-04-191-4/+4
|
* Small doc fix. [CI SKIP]Guo Xiang Tan2015-03-241-1/+1
|
* add `DateTime.now` to list of `TimeHelpers#travel_to` stubbing [ci skip]yuuji.yaginuma2015-03-121-9/+11
|
* Merge pull request #18526 from vipulnsward/add-silence-streamRafael Mendonça França2015-02-051-0/+42
|\ | | | | Extracted silence_stream method to new module in activesupport/testing
| * - Extracted silence_stream method to new module in activesupport/testing.Vipul A M2015-01-201-0/+42
| | | | | | | | | | | | | | | | | | | | | | | | - Added include for the same in ActiveSupport::Test. - Removed occurrences of silence_stream being used elsewhere. - Reordered activesupport testcase requires alphabetically. - Removed require of silence stream from test_case - Moved quietly method to stream helper - Moved capture output to stream helper module and setup requires for the same elsewhere
* | Change AS::Testing::TimeHelpers#travel_to to also stub DateTime.nowYuki Nishijima2015-02-031-0/+1
| |
* | introduce `ActiveSupport::Testing::FileFixtures`.Yves Senn2015-01-281-0/+34
|/ | | | | | It's a thin layer to provide easy access to sample files throughout test-cases. This adds the directory `test/fixtures/files` to newly generated applications.
* Better fork detection in ActiveSupport::Testing::Isolationdeepj2015-01-101-3/+1
| | | | | Process.respond_to?(:fork) returns false if fork is not available. More on http://www.ruby-doc.org/core-2.0.0/Process.html#method-c-fork
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
|
* Merge pull request #17302 from ↵Rafael Mendonça França2014-10-181-2/+2
| | | | | | claudiob/replace-slower-block-call-with-faster-yield Replace (slower) block.call with (faster) yield
* Revert "Replace (slower) block.call with (faster) yield"Zachary Scott2014-10-181-2/+2
| | | | This reverts commit 0ab075e75f58bf403f7ebe20546c7005f35db1f6.
* Replace (slower) block.call with (faster) yieldclaudiob2014-10-181-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Performance optimization: `yield` with an implicit `block` is faster than `block.call`. See http://youtu.be/fGFM_UrSp70?t=10m35s and the following benchmark: ```ruby require 'benchmark/ips' def fast yield end def slow(&block) block.call end Benchmark.ips do |x| x.report('fast') { fast{} } x.report('slow') { slow{} } end # => fast 154095 i/100ms # => slow 71454 i/100ms # => # => fast 7511067.8 (±5.0%) i/s - 37445085 in 4.999660s # => slow 1227576.9 (±6.8%) i/s - 6145044 in 5.028356s ```
* Use `safe_constantize`.Guo Xiang Tan2014-09-021-5/+1
| | | | Fixes https://github.com/rails/rails/issues/9933.
* Fix rounding errors with #travel_to by resetting the usec on any passed time ↵David Heinemeier Hansson2014-08-171-1/+5
| | | | to zero, so we only travel with per-second precision, not anything deeper than that.
* Prefer to pass block when logging.Guo Xiang Tan2014-07-181-1/+1
| | | | | | | | The Logger by default includes a guard which checks for the logging level. By removing the custom logging guards, we can decouple the logging guard from the logging action to be done. This also follows the good practice listed on http://guides.rubyonrails.org/debugging_rails_applications.html#impact-of-logs-on-performance.
* Make the isolated tests run on JRubyRobin Dupret2014-06-211-6/+16
| | | | | | | | | | | | | | As there is no forking on JRuby, we need to spawn sub-processes to make the tests run in isolation. Previously, we were defining globally env variables and running the test file through backticks and delete these variables once the test ran. Now, we simply rely on IO.popen as this is cross-platform and the env variables are available during the child-process execution only so there are no race conditions. [Ben Browning & Robin Dupret]