Why is guard stopping? - ruby-on-rails

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...

Related

How to setup error 404 page in Ruby on Rails system testing

Rails 5.1 introduced system testing that uses Capybara with Selenium to test the UI of Rails application.
I'm wondering to how to use this system testing to test the UI of error pages.
For standard controller tests, we can do something like below to assert response to be 404.
test 'should get not_found' do
get errors_not_found_url
assert_response :not_found
end
But for system tests, if I go to a 404 page, exception will be thrown in controller level and tests terminate immediately without rendering the page.
test '404 page should render with the correct title' do
# act.
visit NOT_FOUND_URL
# assert.
assert_equal("#{APP_NAME} - #{TITLE_404}", page.title)
end
Exception is thrown in controller level.
$ rails test test/system/error/error_page_test.rb
Run options: --seed 30076
# Running:
Puma starting in single mode...
* Version 3.9.1 (ruby 2.3.1-p112), codename: Private Caller
* Min threads: 0, max threads: 1
* Environment: test
* Listening on tcp://0.0.0.0:55237
Use Ctrl-C to stop
2017-07-09 11:10:45 +1200: Rack app error handling request { GET /books/12345678 }
#<ActionController::RoutingError: Could not find book '12345678' by id or name>
/myapp/app/controllers/books_controller.rb:7:in `index'
/Users/yze14/.rvm/gems/ruby-2.3.1/gems/actionpack-5.1.2/lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
/Users/yze14/.rvm/gems/ruby-2.3.1/gems/actionpack-5.1.2/lib/abstract_controller/base.rb:186:in `process_action'
...
Under development/test environment, config.consider_all_requests_local can be set to false in order to show error page instead of stracktrace. But this doesn't swallow exception during system tests.
If you don't want Capybara to re-raise server exceptions in the tests you can set Capybara.raise_server_errors = false.
Secondly, you should check your Gemfile and make sure any gems like web-console,better-errrors, etc are only loaded in the development environment (not in the test environment)
Finally, you shouldn't be using assert_equal with title, you should be using the Capybara provided assert_title which includes waiting/retrying behavior and will reduce potential flakiness in tests.
assert_title("#{APP_NAME} - #{TITLE_404}")

Can't use guard-minitest in Rails

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Š²

Why is Guard Livereload not starting the server?

I have setup Guard and Guar-Livereload on my new Rails project similarly on how I had on a previous one: Gemfile:
group :development do
gem 'spork-rails', '4.0.0'
gem 'guard-spork', '1.5.0'
gem 'childprocess'
gem "rspec-rails"
gem 'guard-livereload', require: false
gem 'spring'
gem "guard-rspec"
end
And in my Guardfile:
guard 'livereload' do
watch(%r{app/views/.+\.(erb|haml|slim)$})
watch(%r{app/helpers/.+\.rb})
watch(%r{app/assets/.+\.rb})
watch(%r{app/assets/.+\.(css|js|scss|jpg|png)})
watch(%r{public/.+\.(css|js|html)})
watch(%r{config/locales/.+\.yml})
# Rails Assets Pipeline
watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html|png|jpg))).*}) { |m| "/assets/#{m[3]}" }
end
Which was created after issuing the command guard init guard-livereload. When I issue guard I can see the following messages:
18:35:41 - INFO - Guard is using TerminalTitle to send notifications.
18:35:43 - INFO - Guard::RSpec is running
18:35:43 - INFO - LiveReload is waiting for a browser to connect.
18:35:43 - INFO - Guard is now watching at '/Volumes/volume/Users/myuser/Documents/RubyApps/myapp'
[1] guard(main)>
But the server doesn't start, however if I rails s the server will start and visible on the front end. This leads me to believe the issue is with Guard. Can anyone point me in the right direction?
Many thanks
EDIT Added console after running guard -d:
18:31:56 - DEBUG - Command execution: emacsclient --eval '1' 2> /dev/null || echo 'N/A'
18:31:56 - INFO - Guard is using TerminalTitle to send notifications.
18:31:57 - DEBUG - Command execution: hash stty
18:31:57 - DEBUG - Guard starts all plugins
18:31:57 - DEBUG - Hook :start_begin executed for Guard::RSpec
18:31:57 - INFO - Guard::RSpec is running
18:31:57 - DEBUG - Hook :start_end executed for Guard::RSpec
18:31:57 - DEBUG - Hook :start_begin executed for Guard::LiveReload
18:31:57 - DEBUG - Hook :start_end executed for Guard::LiveReload
18:31:57 - INFO - LiveReload is waiting for a browser to connect.
18:31:57 - INFO - Guard is now watching at '/Volumes/fenix/Users/wagner/Documents/htdocs/RubyApps/turing'
18:31:57 - DEBUG - Start interactor
18:31:57 - DEBUG - Command execution: stty -g 2>/dev/null`
look at #ec2's recent comment on this:
for livereload, run guard with the '-d' option (bundle exec guard -d) and you should see Hook :run_on_modifications_begin executed for Guard::LiveReload. Let us know if you get that message or not (next step depends on the answer). And of course, make sure livereload is actually turned on in your browser (I have to enable it every time I start the project) - ideally, just open a static html file in the browser, edit that file and check - it should work.

Guard no longer detecting file changes with Yosemite OSX 10.10

I set up a clean install of Yosemite and can't get guard to detect whenever a file is changed.
My Environment:
guard (2.6.1)
guard-minitest (2.2.0)
rubygems-bundler (1.4.4)
Ruby 1.9.3 and 2.0.0 both have been testing
Here is the output from debugging:
tom#Toms-MBP:~/Sites/tick (master)$ LISTEN_GEM_DEBUGGING=2 bundle exec guard -d
I, [2014-10-27T15:34:53.417196 #1059] INFO -- : Celluloid loglevel set to: 0
15:34:53 - DEBUG - Command execution: emacsclient --eval '1' 2> /dev/null || echo 'N/A'
15:34:53 - INFO - Guard is using TerminalTitle to send notifications.
15:34:53 - DEBUG - Command execution: hash stty
15:34:53 - DEBUG - Guard starts all plugins
15:34:53 - DEBUG - Hook :start_begin executed for Guard::Minitest
15:34:53 - INFO - Guard::Minitest 2.3.2 is running, with Minitest::Unit 4.7.5!
15:34:53 - DEBUG - Hook :start_end executed for Guard::Minitest
15:34:53 - INFO - Guard is now watching at '/Users/tom/Dropbox/Sites/tick'
15:34:53 - DEBUG - Command execution: sysctl -n hw.ncpu
D, [2014-10-27T15:34:53.517668 #1059] DEBUG -- : Adapter: considering TCP ...
D, [2014-10-27T15:34:53.517749 #1059] DEBUG -- : Adapter: considering polling ...
D, [2014-10-27T15:34:53.517776 #1059] DEBUG -- : Adapter: considering optimized backend...
I, [2014-10-27T15:34:53.587089 #1059] INFO -- : Record.build(): 0.06837701797485352 seconds
15:34:53 - DEBUG - Command execution: stty -g 2>/dev/null
15:34:53 - DEBUG - Start interactor
[1] guard(main)>
I am not sure how to test the underlying listen gem, but seems like it has to be related. I have confirmed that guard works correctly with polling (bundle exec guard start --force-polling).
I was able to resolve my issue by moving the files out of Dropbox. Once I saw this working, I knew that Dropbox was somehow causing the issue with the file system. I resolved it by removing the folder and re-adding it through Dropbox and now everything is working as before.
I had the same problem, and only thanks to a warning issued by the LiveReload application I fixed it.
Because the problem is not restrained to Dropbox and/or ruby on rails, I wanted to share what I did:
Rename problematic folder (in my case containing the Guardfile)
Create new folder with the old folders name
Move files from old to new folder
Other solutions mentioned by LiveReload are:
rebooting the computer
checking the disk and repairing permissions via Disk Utility
adding the folder to Spotlight privacy list (the list of folders to not index), and then removing from it, effectively forcing a
reindexing
renaming the folder, and then possibly renaming it back
re-creating the folder and moving the old contents back into it
Read more: http://feedback.livereload.com/knowledgebase/articles/86239
This not only fixed my Guard problem, but also allowed Compass watch to run again.
Did you add rb-fsevent gem ?
group :development, :test do
gem 'rb-fsevent' if `uname` =~ /Darwin/
end
if you're using OS X, it will be used OS X FSEvents API.

Guard: how to run specific tags from w/in Guard's console?

I'm using Spork and Guard in my RSpec test suite. I'm excluding slow tests from running with:
RSpec.configure do |config|
...
config.filter_run_excluding slow: true
...
end
Then when I need to I run the slow tests in a separate shell with: $ rspec . --tag slow
I'm wondering if there's a shortcut to run the slow tags in same shell that Guard is auto-running its tests in?
There's a console > prompt? And after looking at documentation I find that typing >. rspec . --tag slow works...but that's just a little more verbose than switching to another shell. Seems like this would be a fairly common request. Ideas?
You can define groups and have different rspec configurations in each group.
Append the code below to the contents of /Guardfile:
scope group: :fast
group :fast do
guard 'rspec', cli: '--tag ~slow' do
# code for watching
end
end
group :slow do
guard 'rspec', cli: '--tag slow' do
# code for watching
end
end
When you start Guard, it defaults to the fast specs:
$ guard
21:56:35 - INFO - Guard::RSpec is running
21:56:35 - INFO - Guard is now watching at '/Users/michi/testproject'
[1] {Fast} guard(main)>
Pressing enter will run all fast specs:
22:02:00 - INFO - Run Fast
22:02:00 - INFO - Running all specs
Run options: exclude {:slow=>true}
Now you can run just all the slow ones by pressing slow:
[2] {Fast} guard(main)> slow
22:02:50 - INFO - Run Slow
22:02:50 - INFO - Running all specs
Run options: include {:slow=>true}
You can also switch the scope to the slow specs and run them all by pressing enter:
[3] {Fast} guard(main)> scope slow
[4] {Slow} guard(main)>
22:03:30 - INFO - Run Slow
22:03:30 - INFO - Running all specs
Run options: include {:slow=>true}
Hope that helps!
This code will run all the test that are tagged "fast" inside the files we are watching.
guard 'rspec', :version => 2, :cli => "--tag ~fast" do
# code for watching
end
You need to use cli option to run only the tests you need.

Resources