Michael Hartl's RoR tutorial 3.2 - ruby-on-rails-3

Following Michael Hartl's ROR tutorial getting this weird error after following the instructions in section 3.2 Tests.
I run the command: bundle exec rspec spec/requests/static_pages_spec.rb
I get the error:
bundle exec rspec spec/requests/static_pages_spec.rb
/Users/name/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in load': no such file to load -- /Users/name/Desktop/ROR/sample-app/spec/requests/spec/requests/static_pages_spec.rb (LoadError)
from /Users/name/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:inblock in load_spec_files'
from /Users/name/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in map'
from /Users/name/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:inload_spec_files'
from /Users/name/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in run'
from /Users/name/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:inrun'
from /Users/name/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'
any help would be appreciated

The error message indicates that it's looking for the file in /Users/name/Desktop/ROR/sample-app/*spec/requests/spec/requests/*static_pages_spec.rb
Are you already in the spec/requests/ directory when trying to run this command? The assumption is that you're in the project's home directory; if you're already in spec/requests/, you can just run:
bundle exec rspec static_pages_spec.rb

Related

Running into issues installing gitlab-shell

I am trying to install Gitlab CE from source and following this installation guide.
When I attempt to install the gitlab-shell using the command provided.
sudo -u git -H bundle exec rake gitlab:shell:install REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production SKIP_STORAGE_VALIDATION=true
I received the following stack trace error.
WARNING: This version of GitLab depends on gitlab-shell 4.1.1, but you're running Unknown. Please update gitlab-shell.
rake aborted!
Gitlab::TaskFailedError: Gitlab::TaskFailedError
/home/git/gitlab/lib/tasks/gitlab/task_helpers.rb:87:in `run_command!'
/home/git/gitlab/lib/tasks/gitlab/task_helpers.rb:164:in `clone_repo'
/home/git/gitlab/lib/tasks/gitlab/task_helpers.rb:157:in `checkout_or_clone_tag'
/home/git/gitlab/lib/tasks/gitlab/shell.rake:16:in `block (3 levels) in <top (required)>'
/usr/local/bin/bundle:22:in `load'
/usr/local/bin/bundle:22:in `<main>'
Tasks: TOP => gitlab:shell:install
What config file should I be modifying to fix my issue? Do I need to modify the Redis URL even though I am using the default configuration? By the way, this install is on an Ubuntu 16.04 server.
This might be caused by using a version of git that is too old.
To debug: append the --trace option to bundle exec to get more info on where this error is coming from and inspect the source.

Installing/Running Thin Webserver on Rails 3

Having an issue running the "Thin" web server. It looks like installation was successful but when I run "thin start" It appears as though Thin starts to initialize but then cannot find some resources it needs.
Below, is the audit trail from my terminal session. Can someone offer a hand with this? According to the Thin docs, installation was done correctly. Thanks
Rails 3.2.12
ruby 1.9.3
root#pgateway:/var/www/testapp# gem install thin
Fetching: eventmachine-1.0.0.gem (100%)
Building native extensions. This could take a while...
Fetching: daemons-1.1.9.gem (100%)
Fetching: thin-1.5.0.gem (100%)
Building native extensions. This could take a while...
Successfully installed eventmachine-1.0.0
Successfully installed daemons-1.1.9
Successfully installed thin-1.5.0
3 gems installed
root#pgateway:/var/www/testapp# thin start
>> Using rack adapter
>> Thin web server (v1.5.0 codename Knife)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
/usr/local/rvm/gems/ruby-1.9.3-p385/gems/thin-1.5.0/lib/thin/backends /tcp_server.rb:16:in `connect': cannot load such file -- thin/connection (LoadError)
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/thin-1.5.0/lib/thin/backends/base.rb:55:in `block in start'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `call'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run_machine'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/thin-1.5.0/lib/thin/backends/base.rb:63:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/thin-1.5.0/lib/thin/server.rb:159:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/thin-1.5.0/lib/thin/controllers/controller.rb:86:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/thin-1.5.0/lib/thin/runner.rb:187:in `run_command'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/thin-1.5.0/lib/thin/runner.rb:152:in `run!'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/thin-1.5.0/bin/thin:6:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p385/bin/thin:19:in `load'
from /usr/local/rvm/gems/ruby-1.9.3-p385/bin/thin:19:in `<main>'
from /usr/local/rvm/gems/ruby-1.9.3-p385/bin/ruby_noexec_wrapper:14:in `eval'
from /usr/local/rvm/gems/ruby-1.9.3-p385/bin/ruby_noexec_wrapper:14:in `<main>'
You seem to install thin separate from rails
Add it to your gemfile and you should be fine
If you want to use a gem, it must be in your Gemfile. You can solve your problem as follows:
Add the following line to your Gemfile: gem 'thin'
Update your current app's environment: bundle install
Then start server
Try to execute the following command:
cd to/your/rails/app
echo 'gem "thin"' >> Gemfile
thin start
this content from https://github.com/macournoyer/thin/issues/115

ActiveRecord Causing SQLException in Rspec Test

UPDATE: My issue is definitely related to this one - it's an issue with ActiveRecord. Still not solved.
I'm trying to get a test to pass in rspec and can't figure out what's going wrong... Here's what I'm getting:
Running: spec/models/user_spec.rb
.
.
.
........F
Failures:
1) User when email address is already taken
Failure/Error: user_with_same_email.save
ActiveRecord::StatementInvalid:
SQLite3::SQLException: near "SAVEPOINT":
syntax error: SAVEPOINT active_record_1
# ./spec/models/user_spec.rb:64:in `block (3 levels) in <top (required)>'
Finished in 0.22908 seconds
9 examples, 1 failure
Here's the related line in my test:
user_with_same_email.save
it breaks when trying to write to the db. Development is fine - no issues.
Thanks
The issue was an old version of sqlite. I installed Homebrew and ran brew install sqlite3
A number of errors came up due to files that already existed. I just renamed them *.old and ran brew link sqlite3. Problem solved!

rake db:migrate aborted! on US-ASCII using rake 0.9.2.2 and rails 3.0.10

Recently I upgraded my gems and started adding new stuff to my app like authentication by third party social websites using omniauth gem. On development environment everything is fine and works like a charm.
I am deploying to staging and production servers using capistrano. Basic deployment is fine and working so far, but I have got really strange problems when I want to do migrations when deploying.
I get the following error messages from capistrano:
[my.server.com] executing command
*** [err :: my.server.com] rake aborted!
*** [err :: my.server.com] "\xC5" on US-ASCII
*** [err :: my.server.com]
*** [err :: my.server.com] (See full trace by running task with --trace)
command finished in 2472ms
I was googling all around and couldn't find any relevant solution. I also tried to downgrade rake gem back to 0.8.7 but with no success on the end - the same errors.
After hours of googling and digging in I found the solution that (I hope) may by helpful for someone with a similar or the same problem.
I did bundle exec rake --trace db:migrate on the staging server and got the following error messages:
rake aborted!
"\xC5" on US-ASCII
/var/www/myapp/test.myapp.com/releases/20111230233802/config/application.rb:5:in `read'
/var/www/myapp/test.myapp.com/releases/20111230233802/config/application.rb:5:in `<top (required)>'
/var/www/myapp/test.myapp.com/releases/20111230233802/Rakefile:4:in `require'
/var/www/myapp/test.myapp.com/releases/20111230233802/Rakefile:4:in `<top (required)>'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `block in load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `block in run'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/bin/rake:19:in `load'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/bin/rake:19:in `<main>'
So I jumped in to the config/application.rb file to find out what could rise the error. Line 5 of that file loads an external config file:
require 'yaml'
APP_CONFIG = YAML.load(File.read(File.expand_path('../app_config.yml', __FILE__)))
and that external file contains UTF-8 chars, not US-ASCII. So I tried a couple of different solutions to solve that problem.
The only one which worked for me was to add an extra few lines of code on top of config/application.rb file:
if RUBY_VERSION =~ /1.9/
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
end
just to tell rake to load external files using utf-8 encoding. After that change everything went smooth and exactly as expected. Problem solved!
PS.
I really don't know why developers of rake 0.9 have changed previous behavior of rake 0.8 which worked fine for me and probably for you as well for a long time. Maybe you have an idea why? I am very curious.

bundle exec rspec VS rspec spec

Ruby 1.9.2 Rails 3.1
Here is the problem bundle exec rspec spec/ does not work, but rspec spec/ runs ok.
When I run c:\RailsInstaller\work\apptwit>bundle exec rspec spec/ (this is the directory where my app is located, so the path to spec would not need to be specified)
I receive
c:/RailsInstaller/work/apptwit/spec/controllers/pages_controller_spec.rb:1:in `require': no such file to load -- spec_he lper (LoadError)
from c:/RailsInstaller/work/apptwit/spec/controllers/pages_controller_spec.rb:1:in `<top (required)>'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:i
n `load'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:i
n `block in load_spec_files'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:i
n `map'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:i
n `load_spec_files'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/command_line.rb:18:in
`run'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:80:in `run_i
n_process'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:69:in `run'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:10:in `block
in autorun'
/spec directory exists as exists spec_helper.rb in it.
So basically I have 2 questions:
Why doesn't bundle exec rspec spec/ work while rspec spec/ has no problems?
What is the difference between those two commands?
Take a look at this answer. bundle exec changes your $PATH, or %PATH% in case of Windows. As a result, by using bundle exec rspec you're calling the RSpec's version which is specified in your Gemfile. rspec ran without Bundler executes the one in your $PATH.
The error you see might be caused by the fact that the RSpec version in your $PATH is incompatible with Rails version you're working with. The version installed and executed by Bundler (with bundle exec rspec) is compatible and works fine.