I want to change my default drive for running tests with javascript, specific scenario with javascript, from default, :selenium, to any, like :webkit, in RSpec, just setting :js => true flag. But, trying to runing "describe 'xxx', :js => true do" with :webkit, and loading javascript_driver in rspec_helper, thats what happened "Undefined method javascript_driver for Capybara:Module"
undefined method `javascript_driver=' for Capybara:Module (NoMethodError)
how I defined loader :webkit in file spec_helper.rb:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
Capybara.javascript_driver = :webkit
Version of Capybara is 1.1.2
Gem File:
source 'https://rubygems.org'
gem 'rails', '3.2.5'
gem 'pg', '0.12.2'
gem "meta_search"
# Bootstrap and layouting
gem 'bootstrap-sass', '2.0.3'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'
gem 'rails3-jquery-autocomplete'
#test support
gem 'faker', '1.0.1'
#login rules
gem 'devise'
gem 'cancan'
#criptar
gem 'bcrypt-ruby', '3.0.1'
#BR
gem 'brazilian-rails'
gem 'rails-i18n'
group :development do
gem 'annotate', '~> 2.4.1.beta'
gem 'nested_scaffold'
end
group :development, :test do
gem 'rspec-rails', '2.11.0'
gem 'guard-rspec', '0.5.5'
gem 'guard-spork', '0.3.2'
gem 'spork', '0.9.0'
gem 'ruby-debug19'
gem 'linecache19'
gem 'factory_girl_rails', '1.4.0'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.4'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.0'
group :test do
gem 'capybara', '1.1.2'
gem 'capybara-webkit'
gem "launchy"
gem 'ZenTest'
#MAC OS Especific
gem 'rb-fsevent', '0.4.3.1', :require => false
gem 'growl', '1.0.3'
#Cucumber
gem 'cucumber-rails', '1.2.1', require: false
gem 'database_cleaner', '0.7.0'
end
group :production do
#gem 'pg', '0.12.2'
end
Thanks for you advanced.
missing this on spec_helper.rb
require "capybara/rspec"
Thanks https://github.com/jnicklas
Related
I have installed a gem rspec-rails. Everything is working fine except ActiveJob.
I have tried to implement the ActiveJob in RSpec with:
include ActiveJob::TestHelper
and here's the code for the RSsec Job Controller:
describe "#perform_later" do
it "Send Invoice Reminder" do
ActiveJob::Base.queue_adapter = :test
InvoiceReminderJob.perform_later
expect(InvoiceReminderJob).to have_enqueued_job
end
end
spec_helper.rb:
require 'rails_helper'
RSpec.describe InvoiceReminderJob, type: :job do
include ActiveJob::TestHelper
# pending "add some examples to (or delete) #{__FILE__}"
describe "#perform_later" do
it "Send Invoice Reminder" do
ActiveJob::Base.queue_adapter = :test
InvoiceReminderJob.perform("test")
expect(InvoiceReminderJob).to have_enqueued_job
end
end
end
invoice_reminder_job_spec.rb:
require 'rails_helper'
RSpec.describe InvoiceReminderJob, type: :job do
# include ActiveJob::TestHelper
# pending "add some examples to (or delete) #{__FILE__}"
describe "#perform_later" do
it "Send Invoice Reminder" do
ActiveJob::Base.queue_adapter = :test
InvoiceReminderJob.perform_later
expect(InvoiceReminderJob).to have_enqueued_job
end
end
end
When I am trying to run rspec with the command rspec I am getting the following error:
uninitialized constant ActiveJob (NameError)
Here is my Gemfile:
Here is the gemfile included for my project:
source 'https://rubygems.org'
ruby '2.1.2'
gem 'acts-as-taggable-on', '~> 3.4'
gem 'acts_as_tenant'
gem 'audited', '~> 4.0'
gem 'audited-activerecord'
gem 'aws-sdk', '~> 1.6'
gem 'axlsx'
gem 'best_in_place', '~> 3.0.1'
gem 'bootstrap-generators'
gem 'bootstrap-sass'
gem 'bullet', group: 'development'
gem 'cancancan', '~> 1.10'
gem 'clockwork'
gem 'coffee-rails', '~> 4.1.0'
gem 'daemons'
gem 'delayed_job_active_record'
gem 'devise'
gem 'eefgilm'
gem 'exception_notification'
gem 'figaro'
gem 'font-awesome-rails'
gem 'i18n-js', '>= 3.0.0.rc11'
gem 'jbuilder', '~> 2.0'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'mailman'
gem 'net-ssh'
gem 'paperclip', '~> 4.2'
gem 'pg'
gem 'protected_attributes'
gem 'puma'
gem 'rails', '4.1.5'
gem 'rails-console-tweaks'
gem 'rails-i18n'
gem 'rails_best_practices'
gem 'redcarpet'
gem 'rest-client'
gem 'roo'
gem 'roo-google'
gem 'roo-xls'
gem 'rubocop', require: false
gem 'sass-rails', '~> 5.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'seed_dump'
gem 'simple_form'
gem 'therubyracer', platforms: :ruby
gem 'traceroute'
gem 'twitter-bootstrap-rails'
gem 'uglifier', '>= 1.3.0'
gem 'whenever', :require => false
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
gem 'zip'
group :development do
gem 'capistrano'
gem 'capistrano3-puma'
gem 'capistrano-bundler', require: false
gem 'capistrano-rails', require: false
gem 'capistrano-rvm'
gem 'rails-erd'
gem 'capistrano-rails-console', require: false
gem 'capistrano-maintenance', '~> 1.0', require: false
gem 'letter_opener'
gem 'rspec-rails'
gem 'faker'
end
group :production do
gem 'rails_12factor'
end
group :test do
gem 'shoulda-matchers'
gem 'database_cleaner'
gem 'simplecov'
end
group :development, :test do
gem 'byebug'
gem 'hirb'
gem 'mocha'
gem 'activejob'
gem 'factory_bot_rails'
end
And here is the output of bundle show activejob:
/Users/221/.rvm/gems/ruby-2.1.2/gems/activejob-0
I have tried to search with lots of solution but I am not able to resolve this issue. If anyone could help me with it, I would be really grateful.
You are using rails 4.1.5, ActiveJob is introduced in rails 4.2
This issue is resolved by using the gem "gem 'activejob_backport'
On my local machine all tests are passing but on CircleCI server all test with selenium fails after the scenarios. So it seems like all steps are passing but after scenario it's looking for some template.
Gemfile:
ruby '2.1.1'
gem 'rails', '4.0.2'
gem "unicorn", "~> 4.7.0"
gem "unicorn-rails", "~> 1.1.0"
gem "pg", "~> 0.17.1"
gem "heroku", "~> 3.6.0"
gem "devise", "~> 3.2.2"
gem 'activeadmin', github: 'gregbell/active_admin'
gem "active_admin_importable", "~> 1.1.2"
gem "ransack", github: "activerecord-hackery/ransack"
gem "jquery-rails", "~> 3.0.4"
gem "jquery-ui-rails"
gem 'newrelic_rpm'
gem "omniauth", "~> 1.1.4"
gem "omniauth-facebook", "~> 1.5.1"
gem "fog"
gem "browser", "~> 0.3.2"
gem "premailer-rails", "~> 1.6.1"
gem "hstore-attributes", "~> 0.0.4"
gem 'stripe', :git => 'https://github.com/stripe/stripe-ruby'
gem "uglifier", "~> 2.4.0"
gem 'sass-rails', '~> 4.0.1'
gem 'coffee-rails', '~> 4.0.1'
gem "possessive"
gem 'draper', '~> 1.3'
gem "gravatar_image_tag", "~> 1.2.0"
gem "memcachier", "~> 0.0.2"
gem "dalli", "~> 2.7.0"
group :staging, :demo, :production do
gem "rails_12factor", "~> 0.0.2"
end
group :development do
gem "rack-mini-profiler"
gem 'flatten_migrations'
end
group :development, :test, :staging, :demo do
gem "awesome_print"
gem "factory_girl_rails", "~> 4.3.0"
gem "faker", "~> 1.2.0"
gem "git-smart", "~> 0.1.9"
end
group :test do
gem "shoulda-matchers", "~> 2.5.0"
gem "rspec-rails", "~> 2.14.0"
gem "capybara", "~> 2.2.1"
gem "database_cleaner", "~> 1.2.0"
gem "xpath", "~> 2.0.0"
gem "selenium-webdriver", "~> 2.41.0"
gem "capybara-firebug", '~> 2.0.0'
gem "codeclimate-test-reporter", require: false
gem "timecop", "~> 0.7.0"
gem "cucumber-rails", "~>1.4.0", :require => false
end
gem 'simplecov', '~> 0.7.1'
gem 'protected_attributes'
gem 'rails-observers'
gem 'pry-debugger', group: [:development, :test]
gem 'capybara-screenshot', :group => :test
env.rb
require 'factory_girl'
require 'cucumber/rails'
require 'capybara/firebug'
require 'capybara'
require 'capybara/dsl'
require 'capybara/cucumber'
require 'selenium-webdriver'
require 'capybara-screenshot/cucumber'
Capybara.configure do |config|
config.javascript_driver = :selenium
config.run_server = true
config.default_selector = :css
config.default_wait_time = 10
config.match = :prefer_exact
config.ignore_hidden_elements = false
end
Capybara.register_driver :selenium do |app|
profile = Selenium::WebDriver::Firefox::Profile.new
Capybara::Selenium::Driver.new( app, :browser => :firefox, :profile => profile )
end
ActionController::Base.allow_rescue = false
begin
DatabaseCleaner.strategy = :transaction
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
Cucumber::Rails::Database.javascript_strategy = :truncation
def wait_for_ajax
Timeout.timeout(Capybara.default_wait_time) do
active = page.evaluate_script('jQuery.active')
until active == 0
active = page.evaluate_script('jQuery.active')
end
end
end
error:
Missing template home/index, application/index with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :arb]}. Searched in:
* "/home/ubuntu/wyzyr/app/views"
* "/home/ubuntu/wyzyr/vendor/bundle/ruby/2.1.0/gems/active_admin_importable-1.1.2/app/views"
* "/home/ubuntu/wyzyr/vendor/bundle/ruby/2.1.0/bundler/gems/active_admin-8c2ff62c30be/app/views"
* "/home/ubuntu/wyzyr/vendor/bundle/ruby/2.1.0/gems/kaminari-0.14.1/app/views"
* "/home/ubuntu/wyzyr/vendor/bundle/ruby/2.1.0/gems/devise-3.2.2/app/views"
(ActionView::MissingTemplate)
Possible problem might be in ruby version that is used by CircleCi. In the Gemfile: 2.1.1 but error returns ruby/2.1.0
Anyone know of a more up-to-date version of a Rails Rspec/Guard/Spork/Growl test suite set up?
These used to be great, but have become outdated as Ruby, Rails and the gems upgraded.
http://ygamretuta.me/2011/08/10/rails-3-setting-up-guard-with-rspec-and-spork-with-growl-notifications-in-osx/
https://eq8scrapbook.heroku.com/equivalents_scrap/on_rspec_spork_guard_configuration
Even the M. Hartl Ruby on Rails Tutorial instructions results in Guard tossing up a ChildProcess error and doesn't load the DRb server.
Here's what I've found to fix my problem above:
rails new app_name --skip-test-framework
Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.12'
gem 'bootstrap-sass', '2.1'
gem 'bcrypt-ruby', '3.0.1'
gem 'faker', '1.0.1'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'
gem 'jquery-rails', '2.0.2'
group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.11.0'
gem 'rspec', '2.11.0'
gem 'guard', '1.6.2'
gem 'guard-rspec', '1.2.1'
gem 'guard-spork', '1.4.2'
gem 'spork-rails', '3.2.1'
gem 'spork', '1.0.0rc3'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.5'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.2.3'
end
group :test do
gem 'capybara', '1.1.2'
gem 'factory_girl_rails', '4.1.0'
gem 'database_cleaner', '0.7.0'
gem 'launchy', '2.1.0'
gem 'rb-fsevent', :require => false
gem 'growl', '1.0.3'
end
group :production do
gem 'pg', '0.12.2'
end
Then run this:
bundle update; bundle install; rails g rspec:install; guard init rspec; guard init spork; spork --bootstrap
Guardfile
Put the boostrapped spork block before the rspec block
spec_helper.rb
Put the block starting with "ENV["RAILS_ENV"] ||= 'test'" inside the Spork.prefork block
.rspec
add --drb
Run 'guard' and you should be all set.
When running 'heroku run rake' I get this error:
no such file to load -- faker
/app/lib/tasks/sample_data.rake:1:in `require'
/app/lib/tasks/sample_data.rake:1:in `<top (required)>'
I have gem 'faker', '0.3.1' under group :development, :test do in Gemfile.
I have require 'faker' in sample_data.rake
source 'https://rubygems.org'
gem 'rails', '3.2.11'
gem 'gravatar_image_tag', '0.1.0'
group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.8'
gem 'guard-spork', '1.2.0'
gem 'faker', '0.3.1'
gem 'spork', '0.8.4'
gem 'will_paginate', '3.0'
gem 'webrat', '0.7.1'
gem 'capybara', '1.1.2'
gem 'annotate', '2.5.0'
gem 'factory_girl_rails', '1.0'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.5'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.2'
group :production do
gem 'pg', '0.12.2'
end
Heroku does not install test or development gems by default.
If you want to load fake in your production, you should remove gem 'faker', '0.3.1' from the group :development, :test do and place it outside any group:
source 'https://rubygems.org'
gem 'rails', '3.2.11'
gem 'gravatar_image_tag', '0.1.0'
gem 'faker', '0.3.1'
group :development, :test do
gem 'sqlite3', '1.3.5'
...
However, if you don't want to load fake, you must ensure that your require fake will be required only when the task is invoked:
task :sample_data => :environment do
require 'faker' #must be inside the task.
...
end
Hope it helps.
EDIT
You can tell Bundler to not load the Gem by:
gem 'faker', '0.3.1', :require => false
I got this issue with the "Rub on Rails 3 Tutorial".
Per gabrielhilals answer, the fix was to move require 'faker' to inside the task
before fix:
require 'faker'
namespace :db do
desc "Fill database with sample data"
task :populate => :environment do
...
...
end
end
after fix:
namespace :db do
require 'faker'
desc "Fill database with sample data"
task :populate => :environment do
...
...
end
end
I upgraded to rails 3.1 and I have some problems with my tests now that worked perfectly before.
I get the following warning before the tests:
DEPRECATION WARNING: ActiveRecord::Associations::AssociationCollection is deprecated! Use ActiveRecord::Associations::CollectionProxy instead. (called from at /home/user/rails_projects/project/config/environment.rb:5)
How can I use CollectionProxy instead of AssociationCollection?
Here is my Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.1.0'
gem 'jquery-rails'
gem "therubyracer", "~> 0.9.4"
gem 'carrierwave', '0.5.6'
gem 'haml', '~>3.1.2'
gem 'mysql2', '0.3.7'
gem 'rmagick', '2.13.1'
gem 'sitemap_generator', '2.0.1'
gem 'whenever', '0.6.8', :require => false
gem 'will_paginate', '3.0.pre2'
group :assets do
gem 'sass-rails', " ~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
end
group :development do
gem 'rspec-rails', '2.6.1'
gem 'annotate-models', '1.0.4'
gem 'faker', '0.9.5', :require => false
gem 'ruby-debug19', '0.11.6'
end
group :test do
gem 'rspec-rails', '2.6.1'
gem 'webrat', '0.7.3'
gem 'factory_girl_rails', '1.0'
gem 'spork', '~> 0.9.0.rc'
end
This is my environment.rb:
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Project::Application.initialize!
Thank you!
I had the same problem and fixed it by upgrading to the latest version of will_paginate. So, change this: gem 'will_paginate', '3.0.pre2'
to this: gem "will_paginate", "~> 3.0.2"
Save your Gemfile then do bundle install.