Guard w/ RSpec2, Ruby1.9.3, Rails 3.1.3 - ruby-on-rails-3

I am running Guard successfully with notifications provided by Libnotify.
funkdified#funkdified-laptop:~/railsprojects/sample_app$ guard
Guard uses Libnotify to send notifications.
Guard is now watching at '/home/funkdified/railsprojects/sample_app'
Guard::RSpec is running, with RSpec 2!
Running all specs
...
Finished in 0.06053 seconds
3 examples, 0 failures
If I modify the spec file I am alerted as to the results of the test, both in the terminal and with a popup notification. If I modify a controller file, again tests run normally. However, when I modify routes.rb, the whole things falls on its face and Guard stops working normally and throws up an error. Anyone have any ideas?
Error:
Running: spec/routing
/home/funkdified/.rvm/gems/ruby-1.9.3-p0#rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load': cannot load such file -- /home/funkdified/railsprojects/sample_app/spec/routing (LoadError)
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0#rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `block in load_spec_files'
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0#rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `map'
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0#rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files'
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0#rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in `run'
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0#rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0#rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0#rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `block in autorun
Forgot to mention, if I kill Guard and restart (after making changes to routes.rb) then Guard again performs normally, suggesting that a test has now failed:
funkdified#funkdified-laptop:~/railsprojects/sample_app$ guard
Guard uses Libnotify to send notifications.
Guard is now watching at '/home/funkdified/railsprojects/sample_app'
Guard::RSpec is running, with RSpec 2!
Running all specs
..F
Failures:
1) PagesController GET 'about' returns http success
Failure/Error: get 'about'
ActionController::RoutingError:
No route matches {:controller=>"pages", :action=>"about"}
# ./spec/controllers/pages_controller_spec.rb:22:in `block (3 levels) in <top (required)>'
Finished in 0.0576 seconds
3 examples, 1 failure
Failed examples:
rspec ./spec/controllers/pages_controller_spec.rb:21 # PagesController GET 'about' returns http success

Check your spec directory. It should have a routing sub-directory for routing specs. If not, just create an empty one. Apparently, RSpec does not create any sub-directories under spec when running rails g rspec:install, but guard expects it to be there.

I think you may have the following line in your Guardfile:
watch('config/routes.rb') { "spec/routing" }
If you don't have specs in spec/routing, then don't folder that you don't need. Change the line to:
watch('config/routes.rb') { "spec" }
Now, all your specs will run when you update your routes.rb file.

Related

Michael Hartl Chapter 3.3.1 Rails Test error message

Ive followed the tutorial word by word, and I'm using the Cloud9 platform to follow along.
I'm supposed to run: $ rails test
I'm supposed to get: 2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
I'm not sure if i'm running the wrong command since i'm using Cloud9, but when I run the program the pages work, meaning I shouldn't be getting any errors at all. It's almost as if the test's never run at all. Any ideas?
enter code he(static-pages) $ rails test
Running via Spring preloader in process 5822
Run options: --seed 31158
Running:
...
Finished in 0.554944s, 5.4060 runs/s, 5.4060 assertions/s.
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.1/lib/rails/test_unit/minitest_plugin.rb:9:in aggregated_results': wrong number of arguments (given 1, expected 0) (ArgumentError)
from /usr/local/rvm/gems/ruby-2.3.0/gems/minitest-5.10.2/lib/minitest.rb:597:inreport'
from /usr/local/rvm/gems/ruby-2.3.0/gems/minitest-reporters-1.1.9/lib/minitest/minitest_reporter_plugin.rb:26:in each'
from /usr/local/rvm/gems/ruby-2.3.0/gems/minitest-reporters-1.1.9/lib/minitest/minitest_reporter_plugin.rb:26:inreport'
from /usr/local/rvm/gems/ruby-2.3.0/gems/minitest-5.10.2/lib/minitest.rb:687:in each'
from /usr/local/rvm/gems/ruby-2.3.0/gems/minitest-5.10.2/lib/minitest.rb:687:inreport'
from /usr/local/rvm/gems/ruby-2.3.0/gems/minitest-5.10.2/lib/minitest.rb:141:in run'
from /usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.1/lib/rails/test_unit/minitest_plugin.rb:73:inrun'
from /usr/local/rvm/gems/ruby-2.3.0/gems/minitest-5.10.2/lib/minitest.rb:63:in block in autorun'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/application.rb:161:infork'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/application.rb:161:in serve'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/application.rb:131:inblock in run'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/application.rb:125:in loop'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/application.rb:125:inrun'
from /usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/application/boot.rb:19:in <top (required)>'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:inrequire'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require'
from -e:1:in're
Ugg just found out this question was already answered elsewhere.
Apparently there is a bug in the Minitest Gem file.
I added the code below to the test/test_helper.rb file to resolve it. However, i'm pretty sure there are other ways to resolve it as well.
Minitest::Reporters.use!

Test fails when run together but passes alone

I am new to RSPEC and am testing the controllers.
Sometimes it happens that the test passes alone like
rspec spec/controllers/controller_name_spec.rb
it passes but when I run :-
rspec spec
the test fails, same test that passed earlier.
What can be the reason, is it related to scalability of rspec or an application specific issue.
As I found same issue with integration tests also.
Rails -v => 3.2.11
Ruby -v => 1.9.2p320
Rspec-rails version => 2.13.0
rspec version => 2.13.0
eg:-
Test case :-
it "should do ##something##" do
plans=Plan.pluck(:id)
plans.delete(#user.subscription.plan.id)
#user.subscription.stripe_customer_token= "cus_1l9m6CicQEXZJ0"
#user.save
get 'apply_change_account', {:subscription=>{:plan_id=>plans.sample}}
flash.now[:success].should_not be_nil
response.should redirect_to dashboard_manage_accounts_path
end
Response error message :-
1) DashboardController Dashboard should do ##something##
Failure/Error: flash.now[:success].should_not be_nil
expected: not nil
got: nil
# ./spec/controllers/dashboard_controller_spec.rb:119:in `block (2 levels) in <top (required)>'
Thanks in advance
Try add flash.clear in before block for every test related to flash.
This may or may not solve the problem, but it's essential to test flash related item to avoid flash object been polluted.

Rails Tutorial - weird RSpec behavior

I'm currently in section 10.3.2 of the Rails Tutorial (beta) and ran into some problems with RSpec.
rspec spec/ runs perfectly, however if I do rspec spec/requests/micropost_pages_spec.rb as described in the tutorial I get the following error:
Failures:
1) Micropost pages micropost creation with invalid information should not create a micropost
Failure/Error: before { visit root_path }
ActionView::Template::Error:
undefined method `model_name' for NilClass:Class
# ./app/views/shared/_micropost_form.html.erb:1:in `_app_views_shared__micropost_form_html_erb__567210303736562711_70234980477780'
# ./app/views/static_pages/home.html.erb:8:in `_app_views_static_pages_home_html_erb___61006871036382679_70234970424160'
# ./spec/requests/micropost_pages_spec.rb:11:in `block (3 levels) in <top (required)>'
Performing the test manually in the web browser seems to work perfectly as well.
Not sure if I did something wrong or if there's a "bug" in the tutorial. Can anyone give a hint?
UPDATE 1: Here's a link to the whole project on GitHub.
UPDATE 2: I now found out that when I restart the rails server I get the error, too, when I hit the page the first time. But when I load the page a second time (reload) then it works perfectly.
Found the problem. Rather stupid mistake. In my static_pages_controller.rb I had
def home
def home
#micropost = current_user.microposts.build if signed_in?
end
end
Thanks anyway for the tips.

Devise with Omniauth for facebook authentication

I am running ruby 1.9.2p18, Devise (1.3.4), Rails (3.0.4) and Omniauth (0.2.6).
Currently I have my webpage doing authentication with Devise, and it works fine.
I am trying to also add facebook authentication to it. I followed the instruction from https://github.com/plataformatec/devise/wiki/OmniAuth%3a-Overview .
When I do localhost:3000 I get
LoadError (no such file to load -- omniauth/core):
app/models/user.rb:3:in `<class:User>'
app/models/user.rb:1:in `<top (required)>'
config/routes.rb:6:in `block in <top (required)>'
config/routes.rb:1:in `<top (required)>'
and if refresh the page again sometimes I get
ActionController::RoutingError (No route matches "/")
I looked and under .rvm/gems/ruby-1.9.2-p180/gems/omniauth-0.2.6 I have the directory oa-core/ but not core/ .
I would really appreciate the help, I have no idea how to debug this one!
2 errors are different.
1. Error:
LoadError (no such file to load -- omniauth/core)
You need to add omniauth to your Gemfile and run 'bundle install'. If you've problem with it this Railscast might help:
Railscasts Omniauth 1
Also see 2 Devise videos on Railscasts.
2. Error:
ActionController::RoutingError (No route matches "/")
It says you haven't configured your app to have a main root. The main root is which matches "/".
- First choose which page you would like as landing page you or homepage. If you haven't created one then do it.
- Next you can find all named routes from shell by "rake routes".
- Then open config/routes.rb file and add main root by:
root :to => 'welcome#index'
substitute "welcome#index" with "your_chosen_controllers_name#chosen_method"
Don't add a named route created by Devise because it will end up with infinite loop ("stack level too deep" error).
Note that Devise wiki recommend no to use Devise if you've no prior experience with Rails. In this case I highly recommend to checkout Rails3.1 new has_secure_password? method.
HTH

as_paperclip_bridge initialization error in rails3

I'm trying to use both of PaperClip and ActiveScaffold with help of as_paperclip_bridge in a rails3.0.5 project.
However, following initialization error is occurred when I launch the project.
=> Booting WEBrick
=> Rails 3.0.5 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
C:/Users/ken/Documents/NetBeansProjects/fcheck/vendor/plugins/as_paperclip_bridge/init.rb:10: undefined method bridge' for ActiveScaffold:Module (NoMethodError)
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/plugin.rb:81
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:25:ininstance_exec'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:25:in run'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:50:inrun_initializers'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:49:in each'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:49:inrun_initializers'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:134:in initialize!'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:77:insend'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:77:in method_missing'
from C:/Users/ken/Documents/NetBeansProjects/fcheck/config/environment.rb:7
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:inrequire'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in require'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225:inload_dependency'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:596:in new_constants_in'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225:inload_dependency'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in require'
from C:/Users/ken/Documents/NetBeansProjects/fcheck/config.ru:3
from C:/Ruby187/lib/ruby/gems/1.8/gems/rack-1.2.3/lib/rack/builder.rb:46:ininstance_eval'
from C:/Ruby187/lib/ruby/gems/1.8/gems/rack-1.2.3/lib/rack/builder.rb:46:in initialize'
from C:/Users/ken/Documents/NetBeansProjects/fcheck/config.ru:1:innew'
from C:/Users/ken/Documents/NetBeansProjects/fcheck/config.ru:1
The code in as_paperclip_bridge\init.rb is attempting to call a module method 'ActiveScaffold.bridge' but it coun't be found.
Even though, same code is working without error in rails2.3.8 project.
We can see a big difference of rails initialization code between version 2 and 3.
On rails 2.3.8, plugins are loaded in 'load_plugins' method which is called after 'load_gems' method in initializer.rb. However, rails3 doesn't have initializer.rb and the loading process seems to be totally different.
I also have tried to remove AS gem and install both of AS plugin with as_paperclip_bridge plugin. But, the error haven't disappeared.
Could someone explain why the error is occurring?!
Anyway, I really hope to get any solution or workaround.
Thanks,
Kenichi
Self reply.
I had realized that as_paperclip_bridge was not required for latest ActiveScaffold implementation. (It's including the bridge)
Please make sure to install ImageMagick and RMagick gem to use PaperClip for image files. Or, you may also think 'as_paperclip_bridge should be there'
Thank you,
Kenichi