Rails.application.initialize! command in environment.rb loads the files including route.rb twice when executing test using rspec. It works when executing it in production environment and route file is loaded exactly once. What may be the issue. I am using gemset
group :development,:test do
gem "rails-erd"
gem 'letter_opener'
gem 'spring'
gem 'faker'
gem 'pry-rails'
gem 'pry-byebug'
gem 'rspec-rails'
gem 'factory_girl_rails'
end
Related
I am doing automation testing of a rails app. Using cucumber-rails gem, Poltergeist and Capybara gem.
I get following error's when I run a single scenario or a complete folder of scenarios.
Net::ReadTimeout (Net::ReadTimeout)
I often get Server out of reach error.
Before running a scenario I change my driver with below line
Capybara.current_driver = :poltergeist
A small example is below
Scenario: Mark asset as Sold on Assets Page for leader
Given javascript driver is changed
Given "company_admin" is login
And Create a group
Then logout from "Company Admin"
I usually get error on company admin is login line.
Can anyone please help in fixing this error
below are the testing gems I am currently using or have in my gemfile.
group :development, :test do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'rails_dt'
gem 'spring'
gem 'dotenv-rails'
gem 'pry-rails'
gem 'cucumber-rails', :require => false
gem 'selenium-webdriver'
gem "chromedriver-helper"
# Pry navigation commands via byebug
gem 'pry-byebug'
gem 'factory_girl_rails', '~> 4.0' # easy fixtures
gem 'rspec-rails', '~> 3.0' # better unit testing
gem 'capybara'
gem 'capybara-screenshot'
gem 'rspec-activejob'
gem 'poltergeist'
gem 'valid_attribute' # concise validation testing
gem 'database_cleaner'
gem 'whiny_validation'
end
I really like Miniskirt and Minitest but I am having issues loading the factories.rb file on each run using spork server. It goes:
cannot load such file -- factories (LoadError)
My factories.rb file is located in the /test directory along with my test_helper.rb.
Any tips would be appreciated.
require 'rubygems'
require 'spork'
Spork.prefork do
...
require 'factories'
end
It took me a little trial and error to get everything to work, but I fixed it by switching to spork-minitest and using the master branch of guard-minitest. Here's my test suite:
group :test, :development do
gem 'capybara'
gem 'database_cleaner'
gem 'awesome_print'
gem 'turn'
gem 'guard'
gem 'guard-spork'
gem 'guard-minitest', github: 'guard/guard-minitest'
gem 'guard-livereload'
gem 'terminal-notifier-guard'
gem 'capybara_minitest_spec'
gem 'rb-fsevent', '~> 0.9.1'
gem "spork-minitest", git: "https://github.com/semaperepelitsa/spork-minitest.git"
gem 'miniskirt'
gem 'minitest-spec-rails'
end
Thanks for the help anyway.
Like the headline said, I am getting the aforementioned error when I try to run my rspec tests. The exact error is (word wrapped for readability):
/.rvm/gems/ruby-1.9.3-p374/gems/test-unit-2.4.8/lib/test/unit/testcase.rb:93:in
`<class:TestCase>': uninitialized constant
Test::Unit::TestCase::Assertions (NameError)
The main fix for this problem on the internet seems to be to remove the 'turn' gem, however I don't have the turn gem loaded. Here is my Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.8'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'devise'
gem 'therubyracer'
gem 'mysql2'
gem 'cucumber'
gem 'email_spec'
gem 'cancan'
gem 'rolify'
gem 'libv8'
gem 'simple_form'
group :test, :development do
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'test-unit'
end
group :test do
gem 'cucumber-rails', :require => false
gem 'capybara'
gem 'database_cleaner'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'coffee-rails', '~> 3.2.1'
gem 'bootstrap-sass'
gem 'sass-rails', '~> 3.2.3'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
The part of my code that the test seems to be choking on is when I have this line in my require 'rspec/rails' in my rspec_helper.rb file.
This project used to run rspecs flawlessly. It's only when I did a reinstall of my OS that it began to behave badly.
Any help is greatly appreciated
Since your are not generating a new app, remove the line
gem 'test-unit'
from your Gemfile and remove the gems turn and minitest, followed by a bundle update.
Answer: If you look in my Gemfile, you see a requirement in my group :test, :development for gem 'test-unit'. I commented that out and it works like a charm. Why and how this works I have no idea, if someone would mind explaining go right ahead.
When running autotest, I get the error Could not find ZenTest-4.7.0 in any of the sources. After viewing this article, I deleted gemfile.lock, ran 'bundle install', and then tried rerunning autotest. Now I get the error Could not find rake-10.0.3 in any of the sources. FYI, I am using RBENV, and I have no other problems running my app (rails c, rails s, rake, ...). Here is my gem file (btw, both "missing" files appeared in gemfile.lock):
source 'http://rubygems.org'
gem 'rails', '3.1.3'
gem 'rake'
gem 'pg', '0.13.2'
# Sidekiq handles background jobs, using threading
gem 'sidekiq', '>= 2.6.1'
# Need the following gems for sidekiq/web
gem 'slim'
# if you require 'sinatra' you get the DSL extended to Object
gem 'sinatra', :require => nil
gem 'heroku-api' # Need the API for scaling sidekiq
gem 'json'
gem 'premailer'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.1.4'
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'
# Bundle the extra gems:
gem 'mechanize'
gem 'nokogiri'
gem 'spreadsheet'
gem 'xml-simple'
gem 'faker', '~> 0.3.1'
# 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 do
gem 'rspec-rails'
gem 'ruby-debug19'
end
group :test do
gem 'rspec-rails'
gem 'ZenTest'
gem 'shoulda-matchers'
gem 'webrat', '0.7.1'
gem 'factory_girl_rails'
gem 'ruby-debug19'
end
gem 'geoip'
gem 'thin'
gem 'htmlentities'
I'm not 100% certain, but I think you just do:
gem install ZenTest
and probably
gem install autotest-rails
From within your application directory.
These guys are not managed by your gemfile and bundler
So, I recently moved to bundler, and I'm having issues getting everything working again.
when I run bundle exec rake test:units, I get this error:
....../gems/factory_girl-1.2.4/lib/factory_girl/factory.rb:327:in `factory_by_name': No such factory: user (ArgumentError)
and, I saw in a another stack overflow post that someone fixed the problem by adding
FactoryGirl.find_definitions
but, that errors in saying that I have duplicate definitions (which I don't, cause search)
I even tried having only one factories file. but the error continued.
top of test_helper:
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
require "bundler/setup"
Bundler.require(:test)
test group in gem file
group :test do
gem "cucumber", "~>0.10.3"
gem "cucumber-rails", "0.3.2"
gem "launchy"
gem "hpricot"
gem "gherkin", "~>2.4.0"
gem "capybara", "0.4.1.2"
gem "rspec", "1.3.2"
gem "rspec-rails", "1.3.2"
gem "rspec-core"
gem "rspec-expectations"
gem "webrat", "0.7.0"
gem "database_cleaner"
gem "factory_girl", "1.2.4"
gem "shoulda"
gem "awesome_print"
gem "cobravsmongoose"
end