Upgrading to Rspec rails 3 - ruby-on-rails

Trying to upgrade from 2.14.2,to rspec 3.x get deprication messages
The `:example_group` key in an example group's metadata hash is deprecated. Use the example group's hash directly for the computed keys and `:parent_example_group` to access the parent example group metadata instead. Called from /home/georgi/ruby/xxx/spec/models/user_spec.rb:2:in `<top (required)>'.
This message is showed for every line in spec file that have 'describe'. Gems that i use in test env is
group :development, :test do
gem 'rspec-rails'
end
group :test do
gem 'factory_girl_rails'
gem 'database_cleaner'
gem 'capybara'
gem 'poltergeist'
gem 'selenium-webdriver', '~> 2.42.0'
gem 'shoulda-matchers'
gem 'rspec-retry'
gem 'simplecov'
end
Information from config.raise_errors_for_deprecations! configuration:
https://gist.github.com/tapalilov/b96b4e2f4237e2ecef84
How to remove these deprecation messages and how to change rspec configuration?
Best regards,
Georgi.

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 rspec :Treating `metadata[:execution_result]

problem with 'rspec_junit_formatter' when i doing
bundle exec rspec --format RspecJunitFormatter
i got errors like this,how to fix it?
home/stasyan/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.4/lib/rspec/core/formatters/deprecation_formatter.rb:186:in `puts': Treating `metadata[:execution_result]` as a hash is deprecated. Use the attributes methods to access the data instead. Called from /home/stasyan/.rvm/gems/ruby-2.1.1/gems/rspec_junit_formatter-0.2.0/lib/rspec_junit_formatter/rspec3.rb:43:in `result_of'. (RSpec::Core::DeprecationError)
from /home/stasyan/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.4/lib/rspec/core/formatters/deprecation_formatter.rb:125:in `print_deprecation_message'
from /home/stasyan/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.4/lib/rspec/core/formatters/deprecation_formatter.rb:36:in `deprecation'
from /home/stasyan/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.4/lib/rspec/core/reporter.rb:137:in `block in notify'
from /home/stasyan/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.4/lib/rspec/core/reporter.rb:136:in `each'
from /home/stasyan/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.4/lib/rspec/core/reporter.rb:136:in `notify'
from /home/stasyan/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.4/lib/rspec/core/reporter.rb:107:in `deprecation'
from /home/stasyan/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.4/lib/rspec/core/warnings.rb:11:in `deprecate'
from /home/stasyan/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:455:in `issue_deprecation'
from /home/stasyan/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.4/lib/rspec/core/metadata.rb:319:in `[]'
from /home/stasyan/.rvm/gems/ruby-2.1.1/gems/rspec_junit_formatter-
my Gemfile
group :development, :test do
gem 'capybara'
gem 'database_cleaner'
gem 'factory_girl_rails', '~> 4.0'
gem 'faker', git: 'https://github.com/stympy/faker.git'
gem 'pry'
gem 'rspec-rails', '~>3.0.0'
gem 'selenium-webdriver'
gem 'spork'
gem 'rspec_junit_formatter'
gem 'rspec-core'
end
I will be glad to any proposals .. Thanks
this is a known problem, fixed three months ago...
https://github.com/sj26/rspec_junit_formatter/commit/96f0115f7dabbea623f04b60dc23519683f39cfa
You might want to install the gem as...
gem 'rspec_junit_formatter', :git => 'https://github.com/sj26/rspec_junit_formatter.git'
Your formatter is using functionality that has been deprecated in rspec 3.
It would appear this has been fixed on the master branch of rspec_junit_formatter, although it may not be in a released gem you should be able to get it by specifying it as a git dependency in your Gemfile.

Why do people group rspec under test and development in the Gemfile?

I'm generally clear on bundler Gemfile options, but I'm not sure why rspec (specifically, rspec-rails) should be in both test and development.
Here are my test groupings:
group :development, :test do
gem 'rspec-rails'
gem 'faker'
end
group :test do
gem "factory_girl_rails"
gem "capybara"
gem 'guard-rspec'
gem 'rb-fsevent'
gem 'growl'
end
Does this look ok?
I am quoting the official documentation:
Add rspec-rails to the :test and :development groups in the Gemfile:
group :test, :development do
gem "rspec-rails", "~> 2.6"
end
It needs to be in the :development group to expose generators and rake
tasks without having to type RAILS_ENV=test.

First steps with rspec, want to test method in /lib/app_name/blah.rb

This is rails 3, with rspec.
How to I create the template for my tests, and where should it be in the /spec folder?
would it be:
/spec/lib/app_name/
I have this in my GEM file:
group :development, :test do
gem 'ruby-debug'
gem 'annotate-models', '1.0.4'
gem 'rspec'
gem 'webrat'
gem 'rspec-rails'
end
What do I need to get my first test going now?
Checkout the documentation at http://relishapp.com/rspec/rspec-rails/v/2-5

Resources