I start using MiniTest in my Rails project.
When I run spring rake test, the test works fine.
But I can't run the test by guard-minitest.
bundle exec guard
05:03:24 - INFO - Guard::Minitest 2.4.6 is running, with Minitest::Unit 5.9.0!
05:03:24 - INFO - Running: all tests
Run options: -n spec/apis/user_spec.rb --seed 22566
# Running:
Finished in 0.004998s, 0.0000 runs/s, 0.0000 assertions/s.
0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
05:03:25 - INFO - Guard is now watching at '/Users/ironsand/dev/my_project'
Guardfile
guard :minitest, spring: 'spring rake test' do
watch(%r{^test/models/company_test.rb$})
watch(%r{^test/(.*)\/?test_(.*)\.rb$})
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
watch(%r{^test/test_helper\.rb$}) { 'test' }
end
I wrote the test file name directory to avoid regular expression failer.
The test file is in test/models/company_test.rb.
Where and how can I configure properly to watch the test files by guard?
I guess that the problem here is in watch blocks
Could you try to set the block like that:
guard 'minitest', cmd: 'spring rake test' do
watch('company.rb') { 'company_test.rb' }
watch('company_test.rb')
enŠ²
Related
I've got a bunch of files in test/policies, and I've tried to enhance rake test like so:
# lib/tasks/test.rake
namespace :test do
desc "Test Pundit policies"
Rake::TestTask.new(:policies) do |t|
t.libs << 'test'
t.pattern = 'test/policies/*_test.rb'
end
end
Rake::Task["test"].enhance do
Rake::Task["test:policies"].invoke
end
It works great if I run bin/rake test:all, but bin/rake test now only runs the policy tests, and none of my others.
Can anyone advise what I am doing wrong here? In case it's not clear, I want rake test to run all my tests, just like it used to.
UPDATE
Actually, it's kind of working now, but I've noticed that my functional, unit and integration tests do run now, but only if the policy tests all pass. If any of the policy tests fail, then the rest of my test suite fails to run.
And I don't like the output, notice how there are two blocks of test output below:
[vagrant#vagrant-centos-6-4 vagrant]$ bin/rake test
Run options: --seed 54880
# Running:
.........................
Finished in 0.584530s, 42.7694 runs/s, 56.4556 assertions/s.
25 runs, 33 assertions, 0 failures, 0 errors, 0 skips
Run options: --seed 19900
# Running:
.........................................................
Finished in 4.132299s, 51.0612 runs/s, 128.9839 assertions/s.
I'd prefer if the policy tests output was merged into the same output block as that from my other tests. Any ideas, or is this as good as it's going to get?
Someone else asked the same question and I answered it for them. The solution in my case was to change my code from:
Rake::TestTask.new(:policies) do |t|
to:
Rails::TestTask.new(:policies) do |t|
It just works, and fixes all the issues I was having.
So I get this error when trying to run a Integration test in TestUnit using Capybara.
It's trying to load the URL at file:///
Any ideas?
# Running:
E
Finished in 1.072113s, 0.9327 runs/s, 0.0000 assertions/s.
1) Error:
SignInTest#test_user_signs_in_successfully:
Capybara::Webkit::InvalidResponseError: Unable to load URL: file:/// because of error loading file:///: Unknown error
test/integration/sign_in_test.rb:12:in `block in <class:SignInTest>'
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
[Finished in 6.2s with exit code 1]
[cmd: ["/usr/local/bin/rbenv exec ruby -Itest test/integration/sign_in_test.rb -n 'test_user_signs_in_successfully'"]]
[dir: /Users/user/code/project]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
Ensure this is in test_helper.rb
require "capybara/rails"
I am writing tests for my sidekiq workers and I want them to run when I type "rake" in the terminal. I have that working - I added the following to my Rakefile:
namespace :test do
Rake::TestTask.new(:workers) do |t|
t.libs << "test"
t.pattern = 'test/workers/**/*_test.rb'
end
end
Rake::Task[:test].enhance ["test:workers"]
When I run rake I get something like this as my output:
Run options: --seed 51172
# Running tests:
SS
Finished tests in 0.005594s, 357.5259 tests/s, 0.0000 assertions/s.
2 tests, 0 assertions, 0 failures, 0 errors, 2 skips
Run options: --seed 17561
# Running tests:
S............................................SSSS..SSSSS......
Finished tests in 2.037526s, 30.4291 tests/s, 45.6436 assertions/s.
62 tests, 93 assertions, 0 failures, 0 errors, 10 skips
The S characters are skips - I haven't finished all of my tests yet. So my question is basically - is there a way to merge the two sets of tests after enhancing? Should I be doing something different than an enhance?
If I'm doing anything blatantly wrong please let me know, and thanks for reading this. And just in case it is needed: Rails 4 w/ Ruby 2.0
Try this, change the following:
Rake::TestTask.new(:workers) do |t|
to this:
Rails::TestTask.new(:workers) do |t|
It's a small change, but fixes the problem for me. It means your entire test suite will run with merged output.
there is a simple workaround for this:
bundle exec rake test:all
if you want to see how rails tasks are created look here
I have a rails application that I just threw guard and minitest and my gaurd file is
guard 'minitest', :cli => '--drb --format doc --color' do
# with Minitest::Unit
watch(%r|^test/(.*)\/?test_(.*)\.rb|)
watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
watch(%r|^test/test_helper\.rb|) { "test" }
# Rails
watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/functional/#{m[1]}_test.rb" }
watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
watch(%r|^app/models/(.*)\.rb|) { |m| "test/unit/#{m[1]}_test.rb" }
end
but when i run guard i get a command prompt
bundle exec guard
22:14:12 - INFO - Guard uses TerminalTitle to send notifications.
22:14:12 - INFO - Guard is now watching at '/Users/trace/Sites/application'
1.9.3 (main):0 > 2 + 2
=> 4
Why am i getting this prompt. Any ideas... here are some of the gems i am using
UPDATE...
when i run all minitest then the tests run...but why do i have to run that...any ideas
What your seeing is the Guard interactor, which makes use of Pry. Normally the prompt looks a bit different, so I assume you've a ~/.pryrc file with some configuration. With Guard 1.5.3, released yesterday, Guard ignores ~/.pryrc and only evaluates ~/.guardrc for the Pry configuration, so the normal Pry configuration is separated from the Guard Pry interactor.
When you're seeing this prompt, it means that Guard is waiting and has nothing to do. You can now start working and Guard automatically starts testing your app with minitest according to your file modifications and watcher configuration, or you can manually trigger an action.
You can get a list of the available actions with help guard. Some commands are generated depending on your Guard plugins and groups within your Guardfile. Here's an example of one of my projects:
$ bundle exec guard
09:58:14 - INFO - Guard uses GNTP to send notifications.
09:58:14 - INFO - Guard is now watching at '/Users/michi/Repositories/extranett'
09:58:15 - INFO - Guard::Jasmine starts Unicorn test server on port 8888 in development environment.
09:58:17 - INFO - Waiting for Jasmine test runner at http://dnndev.me:8888/jasmine
09:58:23 - INFO - Run all Jasmine suites
09:58:23 - INFO - Run Jasmine suite at http://dnndev.me:8888/jasmine
09:58:41 - INFO - Finished in 8.853 seconds
09:58:41 - INFO - 896 specs, 0 failures
09:58:41 - INFO - Done.
09:58:41 - INFO - Guard::RSpec is running
09:58:41 - INFO - LiveReload 1.6 is waiting for a browser to connect.
[1] guard(main)> help guard
Guard
all Run all plugins.
backend Run all backend
change Trigger a file change.
coffeescript Run all coffeescript
frontend Run all frontend
jasmine Run all jasmine
livereload Run all livereload
notification Toggles the notifications.
pause Toggles the file listener.
reload Reload all plugins.
rspec Run all rspec
show Show all Guard plugins.
[2] guard(main)> exit
09:59:39 - INFO - Guard::Jasmine stops server.
09:59:39 - INFO - Bye bye...
I use RubyMine, Windows
I wrote test:
class PostTest < ActiveSupport::TestCase
# Replace this with your real tests.
fixtures :posts
test "the truth" do
#first_posts = posts(:first_posts)
assert #first_posts.title == "Ruby on rails"
end
end
But when I run test with rubyMine ( with bottom button I select "test" and run it)
i get this
C:\Ruby187\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:\Ruby187\bin/rake test
Testing started at 1:44 PM ...
(in D:/Projects/TestProject)
Empty test suite.
0 tests, 0 assertions, 0 failures, 0 errors
Test suite finished: 0.031002 seconds
Errors running test:units!
Empty test suite.
Process finished with exit code 1
E.g my test suite is empty, but test suite has one test: "the truth"
When i run tests from console (ruby post_test.rb), I have
D:\Projects\TestProject\test>ruby unit/post_test.rb
Loaded suite unit/post_test
Started
Ruby on rails
.
Finished in 1.7471 seconds.
1 tests, 1 assertions, 0 failures, 0 errorsWhat's wrong?
This bug RubyMine (build 98.47) http://youtrack.jetbrains.net/issue/RUBY-6158