How do I set up a Rails Angular project to test JS? - ruby-on-rails

I am trying to set up my Rails Angular project to provide JS tests. I have tried almost everything that I have found on Google:
Karma (formerly Testacular)
Jasmine + Jasmine-headless-WebKit
Jasminerice
some other tutorials
but I failed with all of them. I'm looking for a way to run unit and e2e tests in the most painless way (it can be in Guard or Karma, I don't care, but it must run it automatically in the background).
Does anyone have some nice article with a nice example of how to achieve this? In my research I have found this, but IMHO it is an example of how to NOT do this.
My actual Gemfile:
source 'https://rubygems.org'
# Use Ruby 1.9.3 instead default Heroku's 1.9.2
# for development I suggest https://gist.github.com/1688857
ruby '1.9.3'
gem 'rails', '3.2.12'
# Use PostgreSQL, which is quite awesome, fast and easy
gem 'pg'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'bootstrap-sass', '~> 2.3.1'
# I heard that you like Compass
gem 'compass'
# Angular.js
gem 'angularjs-rails'
gem 'angularjs-rails-resource'
gem 'angular-ui-rails'
# Assets should be minified before production
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# Serve static pages like a boss
gem 'high_voltage'
# Some user management will be nice
gem 'devise' # User management
# gem 'cancan' # And they privileges
# To use Jbuilder templates for JSON
gem 'jbuilder'
# Be fast and deadly as Puma
#gem 'puma'
# We need also some administration panel, don't we?
gem 'rails_admin'
# Some helpers
gem 'andand'
group :development do
# IRb is ugly. Use Pry for the God's sake
gem 'pry-rails'
# Deploy with Capistrano
# gem 'capistrano'
# or Vlad the Deployer
# gem 'vlad'
# Why bother yourself with rerunning tests? Use Guard
gem 'guard'
gem 'guard-rspec'
gem 'guard-spork'
gem 'guard-livereload'
gem 'guard-jasmine'
gem 'rb-fsevent', require: false
gem 'rb-inotify', require: false
# Who like ugly error pages? We don't.
gem 'better_errors'
gem 'binding_of_caller'
# Prettier documentation
gem 'yard'
end
group :development, :test do
# Use RSpec for testing
gem 'rspec-rails', '~> 2.12.0'
# Test JS using Jasmine
gem 'jasmine'
gem 'jasmine-headless-webkit'
# Some DB table generator
gem 'factory_girl_rails', '~> 4.1.0'
# And fake data generator
gem 'ffaker'
end
group :test do
# Some Gherkins will be also good (to vodka of course)
gem 'turnip', '~> 1.1.0'
# Aww, an of course some web browser will be also apprised
gem 'capybara', '~> 2.0.1'
# Clean DB after tests
gem 'database_cleaner'
# Some nice matchers
gem 'shoulda-matchers'
# Extend your mocks
gem 'bourne', '~> 1.2.1'
# Coverage reports will be nice
gem 'simplecov', require: false
end
PS:
It would be nice if I can create coverage reports in a simple way.

You can use teaspoon it runs your favorite test suite (default is jasmine) and they have a wiki to integrate with angular. Teaspoon integrates with the asset pipeline, so you can throw all the angular gems in there and require them in the teaspoon generated spec_helper.js.
The other cool thing is: they have a guard plugin available as well.

I feel your pain, it took me a bit of trial and error to get all tests running for my Rails app. I ended up using Guard for developer continuous testing for specs, acceptance, and javascripts. Here are the fruits of my labor.
This is the Gemfile snippet you will need to include. It has the required Gems for Guard, Jasmine, Rspec, and Turnip. This setup will work with MRI and JRuby, we run our tests on both.
group :test, :development do
# Guard
gem 'guard-jasmine'
gem "guard-bundler", ">= 1.0.0"
gem "guard-rails", ">= 0.4.0"
gem "guard-rspec", ">= 2.5.2"
gem "rb-inotify", ">= 0.9.0", :require => false
gem "rb-fsevent", ">= 0.9.3", :require => false
gem "rb-fchange", ">= 0.0.6", :require => false
# Rspec
gem "rspec-rails", '~> 2.12.2'
# Jasmine
gem "jasmine", '~> 1.3.1'
gem "jasminerice"
end
group :test do
# Turnip
gem "turnip", '~> 1.1.0'
gem "capybara", '~> 2.0.3'
end
This the full Guardfile that watches Rspec, Turnip, and Jasmine to trigger tests:
guard 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end
guard :jasmine do
watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$}) { 'spec/javascripts' }
watch(%r{spec/javascripts/.+_spec\.(js\.coffee|js|coffee)$})
watch(%r{spec/javascripts/fixtures/.+$})
watch(%r{app/assets/javascripts/(.+?)\.(js\.coffee|js|coffee)(?:\.\w+)*$}) { |m| "spec/javascripts/#{ m[1] }_spec.#{ m[2] }" }
end
Now things get a little tricky. To get Jasmine to properly load up AngularJS for tests I downloaded angular-mocks.js 1.0.7 to the directory spec/javascripts/support/angular-mocks.js. This is used by the spec helper and the jasmine config to run the AnguljarJS specs.
For the spec/javascripts/spec_helper.js.coffee, point it at the Rails app javascript, the angular-mocks.js, and all the javascript specs:
#=require ../../app/assets/javascripts/application
#=require ./support/angular-mocks
#=require_tree ./
For the Jasmine config, spec/javascripts/support/jasmine.yml, the config will need to point at the Rails app javascript and the angular-mocks.js. Here is the we use, but with the comments removed for brevity:
src_files:
- assets/application.js
- spec/javascripts/support/angular-mocks.js
stylesheets:
- stylesheets/**/*.css
helpers:
- helpers/**/*.js
spec_files:
- '**/*[sS]pec.js'
src_dir:
spec_dir: spec/javascripts
With everything set up, you simply have to run bundle exec guard and all the tests will run and be triggered by development changes.

I've written a blog post about a very simple way to set up AngularJS unit testing on a Rails app using the default Jasmine gem. It took a small code change to get things working smoothly, which has been accepted by the Jasmine team.
http://pivotallabs.com/unit-testing-angularjs-using-jasmine/
In an nutshell:
Add jasmine and angularjs-rails to your Gemfile
gem "angularjs-rails"
gem "jasmine", github: "pivotal/jasmine-gem"
Install the gems and run the Jasmine generator
$ bundle install
$ rails g jasmine:install
Add angular to your application.js, before the rest of your application code
//= require angular
//= require_tree .
Create a file named ./spec/javascripts/helpers/angular_helpers.js and add this line
//= require angular-mocks
Now you can include AngularJS implementation files in your app/assets directory and write tests that use the provided mocks. And when you upgrade the angularjs-rails gem, you will get new versions of angular.js and angular-mocks.js at the same time.

You may have some luck checking out the angular boilerplate project it uses grunt as the build system which I realise is not ruby in anyway, however I think when trying to test things with angular your only hope is to go the nodejs/karma route.
This setup watches for changes in your code and runs the tests. However in my limited experience I haven't been able to get it to show the results of the test run. I am not sure whether I am doing something wrong or if it is not supported.
Anyway hope this helps

Related

Net::ReadTimeout Error While Testing Rails App using cucumber, poltergeist

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

Im getting an error when trying to run a cucumber test, which manipulates a confirm dialogue using selenium-webdriver

I just want to get my cucumber test to accept a confirm dialogue, with my cucumber test, I've installed selenium-webdriver and it gives me this error:
unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055) (Selenium::WebDriver::Error::WebDriverError)
I tried running gem update selenium-webdriver, and that didn't work.
Here is my the feature file:
Feature: Delete User
In order to remove an exisiting user
As a user
I want to be able to remove a user from the database
Scenario: User successfully deletes another user
Given I am currently on the Users page
When I select a user to delete
Then the user should no longer visible on the users page
Here is relevant part of the steps file:
Feature: Delete User, Scenario: User successfully deletes another user
When /^I select a user to delete js: true$/ do
page.evaluate_script('window.confirm = function() { return true; }')
find(:xpath, "//a[#href='/users/2?page=1' and #data-confirm='Are you sure?']").click
end
Then /^the user should no longer visible on the users page$/ do
expect(page).to have_no_content "cwl0#aber.ac.uk"
end
Here is the env.rb file:
require 'cucumber/rails'
require 'selenium-webdriver'
Dir["../../spec/factories/*.rb"].each {|file| require_relative file }
ActionController::Base.allow_rescue = false
Remove/comment out the lines below if your app doesn't have a database.
For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
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
Before do
DatabaseCleaner.start
load Rails.root.join('db/seeds.rb')
end
After do |scenario|
DatabaseCleaner.clean
end
Cucumber::Rails::Database.javascript_strategy = :truncation
And here is the gemfile:
source 'https://rubygems.org'
gem 'thin'
gem 'paperclip', '~> 4.1'
gem 'simple-navigation'
gem 'will_paginate', '~> 3.0'
Required by Windows and some Linux platforms when running with Rails 4.1.5!
gem 'tzinfo-data'
Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.5'
Use sqlite3 as the database for Active Record
gem 'sqlite3'
Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
gem 'oauth', '~>0.4.6'
See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
Use jquery as the JavaScript library
gem "jquery-rails", "~> 2.3.0"
gem 'jquery-ui-rails', '4.1.2'
Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
group :test do
gem 'cucumber-rails', :require => false
gem 'launchy'
gem 'database_cleaner'
gem 'selenium-webdriver', "~> 2.38.0"
gem 'rspec-rails', '~> 3.0.0'
gem 'factory_girl_rails'
end
Please can someone suggest the best way of testing this feature, which allows me to accept the confirm dialogue?
Check the version of selenium-webdriver that you are using compared to your version of Firefox for compatibility and make the appropriate version change in your gemfile.lock file. https://selenium.googlecode.com/git/rb/CHANGES
Older Firefox versions can be found here
https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/
In your Gemfile have the following:
group :test do
gem "capybara"
# selenium webdriver is a dependency of Capybara. However it needs updating
# much more frequently to keep up with firefox. Including it in the Gemfile
# allows us to run 'bundle update selenium-webdriver' when this happens.
gem 'selenium-webdriver'
end
Then follow the instructions in the comment i.e. run
bundle update selenium-webdriver

rails guard looking for spec folder but there is no spec folder

This is the first time, I'm trying BDD and testing, I'm trying things by seeing tutorials and my problem is I found that guard is looking for spec folder as defined in its guard file,
but there is no spec folder, I have test folder instead.
when I run
guard
it tries to load spec folder but there is no spec folder. is it okay to edit the guard file to look for test folder instead of spec folder?
Am I supposed to do rspec install?
rails g rspec install
Could not find generator rspec.
my gem file
source 'https://rubygems.org'
gem 'rails', path: '/home/phanindra/rails'
gem 'journey', git: 'https://github.com/rails/journey.git'
gem 'arel', git: 'https://github.com/rails/arel'
gem 'activerecord-deprecated_finders', git: 'https://github.com/rails/activerecord-deprecated_finders'
gem 'sqlite3'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sprockets-rails', git: 'https://github.com/rails/sprockets-rails'
gem 'sass-rails', git: 'https://github.com/rails/sass-rails'
gem 'coffee-rails', git: 'https://github.com/rails/coffee-rails'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'rb-inotify', '~> 0.8.8'
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
group :test, :development do
gem 'cucumber-rails', :require => false
gem 'database_cleaner'
gem 'rspec'
gem 'spork'
gem 'guard'
gem 'guard-rspec'
gem 'launchy'
end
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano', group: :development
# To use debugger
# gem 'debugger'
my guard file
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end
by following the answer on Could not find generator rspec:install.
I have added rspec-rails to my gem file and did bundle install, then rspec generator worked and it generated spec folder.
But it does not have any folders like fixtures or acceptance or functional etc in test folder!!
according to the official document(https://github.com/rspec/rspec-rails#install), I think you should run :
# not: rails g rspec install
rails generate rspec:install
to generate the "spec" folder and "spec/spec_helper.rb" file and other related stuff.
Try adding the Rails Rspec gem to your gem file:
group :development do
gem 'rspec-rails'
end
run bundle install then rails generate rspec:install

Ruby on Rails: 'rails generate plugin' error on rspec

I've been self-learning developing rails plugin.
One referenced tutorial I'm using is here.
Unfortunately, it seemed I got stuck since the first step when I run "rails generate plugin. It's returning an error saying "rspec [not found]".
c:\rails\test\rails generate plugin HelloWorld
create vendor/plugins/hello_world
create vendor/plugins/hello_world/MIT-LICENSE
create vendor/plugins/hello_world/README
create vendor/plugins/hello_world/Rakefile
create vendor/plugins/hello_world/init.rb
create vendor/plugins/hello_world/install.rb
create vendor/plugins/hello_world/uninstall.rb
create vendor/plugins/hello_world/lib
create vendor/plugins/hello_world/lib/hello_world.rb
error rspec [not found]
I tried to look for possible solutions myself. One that I tried was making an update of the project's bundler gem in hope that might come from a bug of plugin compatibility.
anyway, just in case it would help give you guys some clue on where it could go wrong, I also post my GemFile as follows.
source 'http://rubygems.org'
gem 'rails', '3.1.1'
gem 'annotate', ">=2.5.0"
gem 'sqlite3'
gem 'faker', '0.3.1'
gem 'gravatar_image_tag', '1.0.0.pre2'
gem 'will_paginate', '3.0.pre2'
gem 'jquery-rails'
gem 'pg', '0.14.0'
gem 'bundler', '1.2.0.rc.2'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
group :development do
gem 'rspec-rails', '2.6.1'
end
group :test do
gem 'rspec-rails', '2.6.1'
gem 'webrat', '0.7.1'
gem 'factory_girl_rails', '1.0'
end
Any advice would be really appreciated!
I think it's trying to generate template rspec examples for the plugin, but the rspec directory isn't there. Did you run the rspec installer (rails g rspec:install) after adding rspec to your Gemfile?

How do I setup rspec with rails 2.3.8 and bundler?

A lot of the guides I've been finding don't use bundler.
this is the part of the gemfile I'm using for tests:
group :test do
gem "cucumber"
gem "cucumber-rails"
gem "launchy"
gem "hpricot"
gem "gherkin"
gem "capybara"
gem "rspec"
gem "rack"
gem "rspec-rails"
gem "webrat"
gem "database_cleaner"
gem "factory_girl"
gem "shoulda", :require => nil
gem "shoulda-matchers", :git => "https://github.com/thoughtbot/shoulda-matchers"
gem "cobravsmongoose"
gem "rcov"
gem "ZenTest"
gem "autotest-growl"
gem "inherited_resources", "1.0.2"
gem "responders", "0.4.2"
end
But even with all that, the generators never exist.
so doing: script/generate rspec
doesn't work, (can't find the rspec) generator
generators would be installed if the gems were installed as plugins... but I think that just adds bloat to the app, and different gems compile differently on different OSes.
So, anyone have any guides for setting up rspec with bundler with rails 2.3.x?
Setting up RSpec, Guard, and Spork on a Rails 2 project
I've done this a few times now; hopefully this will be helpful to anyone needing to maintain Rails 2.3 apps. This has worked great for the apps I've worked on, but I welcome contributions from others who suggest additional steps.
This guide assumes a Rails 2.3.x project on Bundler
Get rid of any old rspec plugins that are in your project, if any. RSpec bits may be hiding in:
Rakefile
lib/tasks/rspec.rake
vendor/plugins/rspec
(anything else you can find)
RSpec 2 is not compatible with Rails 2; use RSpec 1 (docs). Put the most recent compatible gem versions to your Gemfile:
group :test, :development do
gem 'test-unit', '1.2.3', :require => false # for rspec
gem 'rspec', '~> 1.2', :require => false
gem 'rspec-rails', '~> 1.2', :require => false
gem 'guard', :require => false
gem 'spork', '~> 0.8.0', :require => false
gem 'guard-rspec', :require => false
gem 'guard-spork', :require => false
gem 'growl', :require => false # notifications; optional
gem 'rb-fsevent', :require => false # for OSX; optional
gem 'listen', '>= 0.5.1', :require => false
gem 'machinist', '~> 2.0', :require => false
gem 'database_cleaner', '~> 0.9.1', :require => false
end
The :require => false options are optional, but it helps the app to start up faster in development if it doesn't have to load testing libraries outside of when SpecHelper.rb requires them.
Install the bundle. Use bundle update for any gems that were already in your Gemfile.
Ensure lib/tasks/rspec.rake and spec/spec_helper.rb do not exist.
script/generate rspec
Remove the config.gem line that was added to config/environments/test.rb; the app uses bundler.
spork --bootstrap
Then edit spec/spec_helper.rb and follow the instructions.
Move everything from the stock spec_helper.rb into the prefork block, except:
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
belongs in each_run.
Install database_cleaner. In spec/spec_helper.rb,
In the prefork block:
require 'database_cleaner'
In the each_run block:
DatabaseCleaner.clean
Initialize Guardfile
guard init spork
guard init rspec
Modify the Guardfile's rspec guard to use the correct version and drb (spork):
guard 'rspec', :version => 1, :cli => '--drb --color' do
Modify the Guardfile as appropriate for your project
Run rake spec. You should get no output (if you have no tests). If you get errors, resolve them.
Run guard. No errors? Great, test away!
Problems? Try again more quickly by running spec spec instead of re-running guard.
We still have an app on rails 2.3.8, but we updated it to use bundler (Gemfile), and it has rspec and cucumber working as well.
Make sure you follow the bundler guide to make your app correctly use the Gemfile's gem loading instead of Rails' default: http://gembundler.com/rails23.html
After you get that preinitializer.rb and change the config/boot.rb working correctly, you might need to make sure you're using the right versions of rspec and cucumber.
I think just that generic gem 'rspec-rails' might try installing rspec 2 for you, but that only works on Rails 3 (I believe), so you might need to specifically tell it to use rspec 1.x.
Our test group looks like this (although I think some of these gems may be older than they need to be, it's been awhile since we've updated them since a rails 3 upgrade for the app is pending we're not too worried about what it looks like right now):
group :test, :cucumber do
gem 'autotest-fsevent'
gem 'test-unit', '~>1.2.3'
gem "hoe", "1.5.1"
gem 'autotest-rails', '4.1.0'
gem 'rspec', '1.3.2'
gem 'rspec-rails', '1.3.4'
gem 'cucumber', '0.10.0'#, '0.9.0'
# Change this shinanigans to 0.4.0 when it gets released ;)
gem 'cucumber-rails', '0.3.2'
gem 'database_cleaner', '0.5.2'
gem 'capybara', '0.3.9'
gem 'launchy'
gem 'dupe', '0.5.1'
gem 'factory_girl', '1.2.4'
gem 'email_spec', '~>0.6.2', :require => false
end
After doing this, and running bundle install, I am able to type the command script/generate --help which includes this in the output:
Installed Generators
Rubygems: business_time_config, cucumber, culerity, dupe, email_spec, feature, integration_spec, paperclip, rspec, rspec_controller, rspec_model, rspec_scaffold
Builtin: controller, helper, integration_test, mailer, metal, migration, model, observer, performance_test, plugin, resource, scaffold, session_migration
As you can see, the cucumber and rspec generators are in fact available there.
I think your problem might be the version of rspec it's installing. If it's installing rspec version 2, then that is tied to rails 3, which handles generators in gems differently I believe (I believe they have to be put in a different directory structure). That could be why your rails 2.3.x app isn't seeing them.
You don't have to follow my versions exactly, I'm not a fan (at all) of putting specific versions in a Gemfile but we ended up doing it here way back when because a) we didn't fully understand bundler, and b) We needed to make sure we were getting rails 2.3-compatible gems.
Hopefully this helps! Let me know if you have questions.
The reason the generators don't exist is that when you run rails generate ..., it's executing in the development environment while these gems are only loaded in the test environment.
Option 1
Add them to both development and test environments.
Option 2
Run rails generate ... RAILS_ENV=test
(I'm not positive that this option will work.)
In rails 5.1.4 you there are four easy steps to get your RSpec up and running:
group :development, :test do
gem "database_cleaner"
gem "rspec-rails"
end
Add the above gems to the :test and :development groups in your Gemfile.
run bundle install from the command line
run rails generate rspec:install from the command line, it will create the following files:
create .rspec
create spec
create spec/spec_helper.rb
create spec/rails_helper.rb
configure spec_helper.rb and rails_helper.rb
You can check more detailed info on: https://kolosek.com/rails-rspec-setup.

Resources