1st deploy - need to install all gems on the server - ruby-on-rails-3

I'm trying to deploy for the 1 time to the server ( cap deploy:cold ) and it keep asking me to install gems. Just one example:
*** [err :: ip-address] Could not find net-ssh-2.3.0 in any of the sources
Is there something I could to to install all the gems needed in one shot?
Here is my deploy.rb file, and gemfile:
deploy.rb
set :application, "myapp"
set :repository, "repo goes here"
set :scm, :git
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
role :web, "ipaddress" # Your HTTP server, Apache/etc
role :app, "ipaddress" # This may be the same as your `Web` server
role :db, "ipaddress", :primary => true # This is where Rails migrations will run
# role :db, "your slave db-server here"
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
set :deploy_to, "/home/deploy/#{application}"
set :rails_env, 'production'
set :branch, "master"
set :scm, :git
set :user, "user"
set :runner, "user"
# ssh_options[:port] = 2232
set :use_sudo, false
set :normalize_asset_timestamps, false
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
namespace :bundler do
task :create_symlink, :roles => :app do
shared_dir = File.join(shared_path, 'bundle')
release_dir = File.join(current_release, '.bundle')
run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{release_dir}")
end
task :bundle_new_release, :roles => :app do
bundler.create_symlink
run "cd #{release_path} && bundle install --without test"
end
task :lock, :roles => :app do
run "cd #{current_release} && bundle lock;"
end
task :unlock, :roles => :app do
run "cd #{current_release} && bundle unlock;"
end
end
after "deploy", "deploy:cleanup"
namespace :deploy do
desc "Restarting mod_rails with restart.txt"
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
end
[:start, :stop].each do |t|
desc "#{t} task is a no-op with mod_rails"
task t, :roles => :domain do ; end
end
end
task :after_update_code do
run "ln -nfs #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml"
end
gemfile:
source 'http://rubygems.org'
gem 'rails', '3.1.3'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'json'
gem 'rake', '0.9.2.2'
gem 'mysql2'
gem 'capistrano'
gem 'therubyracer'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.1.5'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug'

maybe if you change this line
run "cd #{release_path} && bundle install --without test"
to
run "cd #{release_path} && bundle install --path=you_gem_path --without #{bundle_without.join(' ')}"
you can find your gem path by running
$ echo $GEM_PATH
you also have to set bundle_without
you can set it in the beginning of file
set :bundle_without, [:development, :test]

try adding this to your deploy.rb
set :bundle_without, [:development, :test]
require 'bundler/capistrano'

Related

CarrierWave not working with Fog -> ArgumentError ( is not a recognized storage provider): app/controllers/notes_controller.rb:11:in `create'

I followed the railscasts about using carrierwave with fog with aws s3 to the T but it doesnt seem to work.
The Gemfile is as follows:
source 'https://rubygems.org'
ruby '1.9.3'
gem 'rails', '3.2.13'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg'
gem 'pg_search'
gem 'devise'
gem "therubyracer"
gem "less-rails" #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS
gem "twitter-bootstrap-rails", :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
gem "simple_form"
gem 'aws-sdk', '~> 1.8.1.2'
gem 'activerecord-reputation-system', require: 'reputation_system'
gem 'bootstrap-will_paginate'
gem 'carrierwave'
gem "rmagick"
gem "fog", "~> 1.3.1"
gem 'carrierwave-aws'
config/initializers/carrierwave.rb
require 'carrierwave'
CarrierWave.configure do |config|
config.fog_credentials = {
provider: "AWS",
aws_access_key_id: ENV["xxx"],
aws_secret_access_key: ENV["yyy"],
region: ENV['ap-southeast-1']
}
config.cache_dir = "#{Rails.root}/tmp/uploads"
config.fog_directory = ENV["ABC"]
end
The uploader:
class ImageUploader < CarrierWave::Uploader::Base
require 'carrierwave/processing/mime_types'
before :store, :remember_cache_id
after :store, :delete_tmp_dir
# Include RMagick or MiniMagick support:
include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
# Choose what kind of storage to use for this uploader:
# storage :file
storage :fog
include CarrierWave::MimeTypes
process :set_content_type
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process :resize_to_limit => [200, 200]
end
# store! nil's the cache_id after it finishes so we need to remember it for deletion
def remember_cache_id(new_file)
#cache_id_was = cache_id
end
def delete_tmp_dir(new_file)
# make sure we don't delete other things accidentally by checking the name pattern
if #cache_id_was.present? && #cache_id_was =~ /\A[\d]{8}\-[\d]{4}\-[\d]+\-[\d]{4}\z/
FileUtils.rm_rf(File.join(root, cache_dir, #cache_id_was))
end
end
end
the controller:
class NotesController < ApplicationController
before_filter :authenticate_user!, only: [:create, :destroy]
before_filter :correct_user, only: :destroy
def index
end
def create
#note = current_user.notes.build(params[:note])
#notes = Note.paginate(page: params[:page])
if #note.save
flash[:success] = "Note uploaded!"
redirect_to root_url
else
flash.now[:error] = "Note failed to upload."
render 'static_pages/home'
end
end
def destroy
#note.destroy
flash[:success] = "Note deleted."
redirect_to root_url
end
private
def correct_user
#note = current_user.notes.find_by_id(params[:id])
redirect_to root_url if #note.nil?
end
end
I don't really know if the problem lies in the gem or the controller. Even the controller is based on the microposts controller in Michael Hartl's book "The Ruby on Rails Tutorial" so I don't know where I have gone wrong.
That's an awfully early version of fog. The latest is 1.12.1. Try updating to the latest release using the following entry in your Gemfile
gem "fog", "~> 1.12.1"

Authlogic / Selenium breaks after rails 3.2.12 upgrade

I'm using Authlogic and having difficulty getting my Selenium tests to work with :js=>true after upgrading to Rails 3.2.12. The same tests use to worked under Rails 3.1.3. I am running my tests using Spork.
I am logging in through Selenium launches Firefox (19.0.2), fills the login form but then I get a permissions error from Authlogic, the standard "You are not allowed to access this action."
I can see that many people are having issues with this but as I mentioned, has only became a problem for me once upgrading from Rails 3.1.3 to Rails 3.2.12. I suspect that the issue may be within my spec_helper file (below) and in particularly within the
module Authlogic
block which I got from here:
Authlogic with Capybara + Cucumber + Selenium Driver not working
**spec_helper.rb**
require 'rubygems'
require 'spork'
require 'authlogic/test_case'
include Authlogic::TestCase
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.color_enabled = true
ApplicationController.skip_before_filter :activate_authlogic
config.before(:each, :type => :request) do
activate_authlogic
end
config.include FactoryGirl::Syntax::Methods
config.include Capybara::DSL
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, :js => true) do
Capybara.current_driver = :selenium
DatabaseCleaner.strategy = :truncation
module Authlogic
module Session
module Activation
module ClassMethods
def controller
if !Thread.current[:authlogic_controller]
Thread.current[:authlogic_controller] = Authlogic::TestCase::MockController.new
end
Thread.current[:authlogic_controller]
end
end
end
end
end
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
config.include(MailerMacros)
config.before(:each) { reset_email }
config.mock_with :mocha
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
end
end
Spork.each_run do
FactoryGirl.reload
end
My understanding is that Authlogic and Selenium Webdriver work on different threads hence the need for this patch in the spec_helper file.
In the Request Spec I get a permissions error from Authlogic. Here is the Request Spec test in question:
# UNIT REQUEST SPEC
require 'spec_helper'
describe "Units" do
describe "GET /admin/units/new" do
before(:each) do
activate_authlogic
UserSession.create FactoryGirl.create(:admin_user, :email => "foo#bar.com", :password => "password", :password_confirmation => "password")
visit root_path
fill_in "user_session[email]", :with => "foo#bar.com"
fill_in "user_session[password]", :with => "password"
click_button "Sign In"
end
it "displays a pop up dialog after unit is created", :focus, :js => true do
visit new_admin_unit_path
fill_in "Title", :with => "Unit Title"
fill_in "Code", :with => "U-TEST"
fill_in "Learning Outcome", :with => "Some Learning Outcome"
fill_in "unit[learning_outcomes_attributes][0][assessment_methods_attributes][0][content]", :with => "Some Assessment Criteria"
click_button "Save and Publish"
page.should have_css('div.ui-dialog')
end
end
end
My Capybara tests are working ok with:
activate_authlogic
UserSession.create FactoryGirl.build(:user)
in the before(:each) block, the problem only arises when using :js=>true
So, my questions are:
Is it a case that with Rails 3.2.x that the spec_helper fix (module Authlogic ... ) no longer works.
If that is in fact the case, what is the "normal" way of getting this to work?
Just revisited this today. When I upgraded Rails I also upgraded capybara to the latest version (2.1.0). It seems that downgrading capybara from this version (2.1.0) to version 2.0.1 seemed to do the trick. I can see that capybara (2.0.1) uses xpath (1.0.0) while capybara (2.1.0) uses xpath (2.0.0) along with a different version of nokogiri gem. I have no idea if there is a link there but here is my gem file if anyone cares to take a look:
source 'http://rubygems.org'
gem 'rails', '3.2.12'
gem 'rack-mini-profiler'
gem 'authlogic'
gem 'rails3-generators'
gem 'mysql2'
gem 'declarative_authorization'
gem 'kaminari'
gem "foreigner"
gem 'validates_timeliness'
gem "activerecord-import", ">= 0.2.0"
gem 'ezcrypto'
gem 'thin'
gem 'exception_notification'
gem 'mail'
gem 'libv8', '~> 3.11.8.0'
gem "therubyracer", :require => 'v8'
gem 'jasmine', :group => [:development, :test]
gem 'sprockets'
gem 'jquery-rails'
gem 'tinymce-rails'
gem 'acts_as_list'
gem 'cocaine'
gem 'rmagick'
gem 'carrierwave'
gem 'remotipart'
gem 'deep_cloneable', '~> 1.4.0'
gem 'delayed_job_active_record'
gem 'daemons'
gem 'rb-readline'
gem "jquery-migrate-rails", "~> 1.0.0"
gem 'ransack'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', "~> 3.2.3"
gem 'coffee-rails', "~> 3.2.1"
gem 'uglifier', '>= 1.0.3'
end
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
group :development, :test do
gem 'cheat'
gem 'ruby-growl'
gem 'letter_opener'
gem 'rspec-rails', "~> 2.0"
gem 'database_cleaner'
gem 'rb-fsevent', '~> 0.9.1'
gem 'guard-rspec'
gem 'spork-rails'
gem 'guard-spork'
gem 'factory_girl_rails'
gem 'capybara', '2.0.1'
gem 'launchy'
gem 'mocha', :require => false
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
end

With Minitest+Guard+Spork, all test suites and support files are being reloaded on each run

I'm running into a problem where everything in my test setup, including Spork's prefork block, is being reloaded and invoked on each run. It is taking 5-8 seconds for a test to fire off after guard picks up a change even though this is a new project so there are minimal tests and I even have an SSD.
Before I realized everything was reloading, I profiled it using the technique described by Jo Liss here and I've included those hanging requires but obviously that didn't help since it's all being reloaded anyway. However, that's when I noticed this:
Loaded Suite
test,test/controllers,test/controllers/manage,test/factories,test/functional/manage,test/helpers,test/helpers/manage,test/integration,test/models,test/support
I'm not seeing why it would reload everything. This is my first attempt at setting up minitest+spork+guard (i should have just gone with rspec, sigh) so I'm hoping it's something stupid. I'm including everything in hopes that someone has run into it or can easily spot what I've missed. Thanks in advance!
My files include:
test_helper.rb
require 'spork'
Spork.prefork do
#MiniTest::Rails.override_testunit!
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'guard'
require 'guard/interactors/readline'
require 'guard/ui'
require 'guard/interactors/coolline'
require 'guard/interactor'
require 'guard/dsl'
require 'guard/notifiers/rb_notifu'
require 'guard/notifier'
require 'guard/minitest/notifier'
require 'guard/minitest/runners/default_runner'
Dir[File.expand_path('test/support/*.rb')].each { |file| require file }
require "mocha"
Spork.trap_method(Rails::Application, :reload_routes!)
Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
end
Guardfile
guard 'bundler' do
watch('Gemfile')
# Uncomment next line if Gemfile contain `gemspec' command
# watch(/^.+\.gemspec/)
end
guard 'spork', :wait => 65, :test_unit => false, :minitest => true, :minitest_env => { 'RAILS_ENV' => 'test' }, :bundler => true do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('test/test_helper.rb') { "test" }
end
guard 'minitest' do
watch(%r|^test/test_helper\.rb|) { "test" }
watch(%r|^test/support/(.*)\.rb|) { "test" }
watch(%r{^test/.+_test\.rb$})
watch(%r|^app/models/(.*)\.rb|) {|m| ["test/models/#{m[1]}_test.rb", "test/integration/#{m[1]}_test.rb"] }
watch(%r|^app/controllers/(.*)\.rb|) {|m| ["test/controllers/#{m[1]}_test.rb", "test/integration/#{m[1]}_test.rb"] }
watch(%r|^app/views/(.*)\.html|) {|m| "test/integration/#{m[1]}_test.rb" }
watch(%r|^app/objects/(.*)\.rb|) {|m| "test/objects/#{m[1]}_object_test.rb" }
end
guard 'livereload' do
watch(%r{app/.+\.(erb|haml)})
watch(%r{app/helpers/.+\.rb})
watch(%r{(public/|app/assets).+\.(css|js|html)})
watch(%r{(app/assets/.+\.css)\.scss}) { |m| m[1] }
watch(%r{(app/assets/.+\.js)\.coffee}) { |m| m[1] }
watch(%r{config/locales/.+\.yml})
end
support/minitest.rb
#require "minitest/autorun"
require "minitest/rails"
require "minitest/spec"
require "minitest/pride"
require "minitest/rails/shoulda"
require "minitest/autorun"
require "capybara/rails"
class RequestSpec < MiniTest::Spec
include Rails.application.routes.url_helpers
include Capybara::DSL
include Rails.application.routes.url_helpers
end
MiniTest::Spec.register_spec_type /integration$/i, RequestSpec
#MiniTest::Spec.register_spec_type /object$/, MiniTest::Spec
class MiniTest::Rails::Controller
include Devise::TestHelpers
end
support/turn.rb
require 'turn'
require 'turn/autorun'
require 'turn/colorize'
require 'turn/reporter'
require 'turn/reporters/pretty_reporter'
Turn.config do |c|
c.natural = true
c.ansi = true
c.format = :pretty
end
Gemfile
source 'https://rubygems.org'
# core
gem 'rails', '3.2.8'
gem 'thin'
# infrastructure
gem 'heroku'
gem 'foreman', :groups => [:development, :test]
# application monitoring
gem 'airbrake'
gem 'newrelic_rpm'
# view engine
gem 'haml', '>= 3.1.7'
gem 'haml-rails', '>= 0.3.5'
gem 'redcarpet' # markdown
# data persistence
gem 'mongoid', '>= 3.0.5'
gem 'redis'
gem 'redis-store'
gem 'redis-rails'
# email
gem 'sendgrid'
gem 'mailcatcher', :group => [:development]
# authentication and authorization
gem 'devise', '>= 2.1.2'
gem 'omniauth', '>= 1.0'
#gem 'authority'
gem 'cancan'
gem 'rolify', '>= 3.2.0'
# view helpers
gem 'bootstrap-generators', '~> 2.1', :group => [:development]
gem 'jquery-rails'
gem 'simple_form', '>= 2.0.2'
gem 'rails3-jquery-autocomplete'
# file attachments
gem 'rmagick'
gem 'fog'
gem 'carrierwave'
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
# url helpers
gem 'mongoid_slug'
# console tools
gem 'ansi', :groups => [:development, :test]
gem 'rack-livereload', :groups => [:development]
gem 'pry-rails', :groups => [:development]
gem 'growl', :groups => [:development, :test]
gem 'turn', :groups => [:test]
gem 'awesome_print'
gem 'progress_bar', :groups => [:test]
# supporting libraries
gem 'bson_ext'
gem 'nokogiri', :group => :test
gem 'ruby_parser', '>= 2.3.1', :group => :test
gem 'rb-fsevent', '~> 0.9.1', :group => :development
# assets
gem 'less-rails', :group => :assets
gem 'therubyracer', '>= 0.10.2', :group => :assets
gem 'uglifier', '>= 1.0.3', :group => :assets
# guard
gem 'guard', :group => :development
gem 'guard-livereload', :group => :development
gem 'guard-spork', :group => :development
gem 'guard-minitest', :group => :development
gem 'guard-bundler', :group => :development
# minitest
gem 'spork-minitest', :group => :test
gem 'minitest-rails', :group => :test
gem 'minitest-rails-shoulda', :group => :test, :git => 'git://github.com/rawongithub/minitest-rails-shoulda.git'
gem 'capybara_minitest_spec', :group => :test
# mocking
gem 'mocha', :group => :test
# http testing
gem 'vcr', :group => :test
gem 'webmock', :group => :test
# factories
gem 'factory_girl_rails'
It appears that Spork and Minitest were actually not working as expected. In order to fix this, the following changes had to be made:
Inside of the Guardfile, :drb => true had to be added to minitest:
guard 'minitest', :drb => true do
#...
end
However that alone will break guard/minitest/spork because it tries to force feed it the -r -e options which are not currently supported. You'll run into the following error:
Running: test/models/business_test.rb
Running tests with args ["-r", "/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/guard-minitest-0.5.0/lib/guard/minitest/runners/default_runner.rb", "-e", "::GUARD_NOTIFY=true", "test/test_helper.rb", "./test/models/business_test.rb"]...
Exception encountered: #<LoadError: cannot load such file -- -r>
backtrace:
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `block in require'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-minitest-0.0.3/lib/spork/test_framework/minitest.rb:13:in `block in run_tests'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-minitest-0.0.3/lib/spork/test_framework/minitest.rb:12:in `each'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-minitest-0.0.3/lib/spork/test_framework/minitest.rb:12:in `run_tests'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:13:in `block in run'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/forker.rb:21:in `block in initialize'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/forker.rb:18:in `fork'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/forker.rb:18:in `initialize'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:9:in `new'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:9:in `run'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/server.rb:48:in `run'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1548:in `perform_without_block'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1508:in `perform'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1586:in `block (2 levels) in main_loop'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1582:in `loop'
/Users/chance/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1582:in `block in main_loop'
Done.
Fortunately, there is a pull request for spork-minitest that fixes it.
Once the gem was pointed over to the repo, it took a nice cut out of the load times. It isn't anywhere near as fast as node.js and mocha, but it is at least faster than rspec.

Capybara get error `block (2 levels) in <top (required)>'

Spent whole day with the problem.
Very simple test. I want to visit main page and check if it has text "Match".
require 'spec_helper'
describe "Sign in" do
it "should sign in with correct data", :js => true do
visit root_path
page.should have_content("Match")
end
end
Running rake spec:requests I've got:
1) Sign in should sign in with correct data
Failure/Error: visit root_path
Timeout::Error:
Timeout::Error
# ./spec/requests/signin_spec.rb:5:in `block (2 levels) in <top (required)>'
Can't fix it. It doesn't work with or without spork and guard, and making me crazy :(
My environment:
Gemfile:
group :test, :development do
gem 'rspec-rails', '2.7.0' , :branch => 'rails3'
gem 'capybara'
gem 'guard'
gem 'guard-rspec'
gem 'guard-spork'
gem 'growl'
gem 'launchy'
gem 'growl_notify', :require => false if RUBY_PLATFORM =~/darwin/i
gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~/darwin/i
end
spec_helper.rb:
require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# Add this to load Capybara integration:
require 'capybara/rspec'
require 'capybara/rails'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = false
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
#config.treat_symbols_as_metadata_keys_with_true_values = true
#config.filter_run :focus => true
#config.run_all_when_everything_filtered = true
end
end
Spork.each_run do
# This code will be run each time you run your specs.
FactoryGirl.reload
end

rails 3.1.rc6 + factorygirl+ devise + spec2 => undefined method `Factory' for #<RSpec::Core::ExampleGroup::

my gem file looks like
source 'http://rubygems.org'
gem 'rails', '3.1.0.rc6'
gem 'sqlite3'
gem 'devise'
gem 'will_paginate'
gem 'therubyracer'
group :assets do
gem 'sass-rails', " ~> 3.1.0.rc"
gem 'coffee-rails', "~> 3.1.0.rc"
gem 'uglifier'
end
gem 'jquery-rails'
group :test do
gem 'turn', :require => false
gem 'rspec-rails'
gem 'webrat'
end
group :development do
gem 'rspec-rails'
gem 'webrat'
gem 'spork'
gem 'factory_girl_rails'
gem 'capybara'
gem 'guard-rspec'
end
my factories.rb
Factory.define :user do |user|
user.username "ccc"
user.email "ccc#eg.com"
user.password "foobar"
user.password_confirmation "foobar"
end
Factory.define :user_hero do |hero|
hero.supername "superman"
hero.association :user
end
my hero_controller_spec looks like this
require 'spec_helper'
describe HerosController do
include Devise::TestHelpers
render_views
before(:each) do
#user = Factory(:user)
# #request.env["devise.mapping"] = :user
# #user = Factory.create(:user)
sign_in #user
#hero_attr = {
:supername => "superman",
}
end
it "should create a new instance with valid attributes" do
#user.heros.create!(#hero_attr)
end
end
My autotest or guard shows up the following message
Failures:
1) HerosController should create a new instance with valid attributes
Failure/Error: #user = Factory(:user)
NoMethodError:
undefined method `Factory' for #<RSpec::Core::ExampleGroup::Nested_1:0x000001028a3998>
# ./spec/controllers/heros_controller_spec.rb:8:in `block (2 levels) in <top (required)>'
Finished in 0.00726 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/controllers/heros_controller_spec.rb:33 # HerosController should create a new instance with valid attributes
in spec_helper.rb
add the following
require 'factory_girl'
load 'factories.rb'
Try this:
#user.HerosController.create!(#hero_attr)
in place of:
#user.create!(#hero_attr)
Factory Girl needs to be in the test group otherwise it never gets loaded when you run your specs. Currently it's loaded only in your development group.
Try this
#user = FactoryGirl(:user)
or
#user = FactoryGirl.create(:user)