I finally want to add real testing to my Rails app and using various tutorials to learn. This github page - https://gist.github.com/kyletcarlson/6234923 - has some great boiler plate examples and I think I'm following it correctly but can't get it to work. I get the following error:
// ♥ rspec
2019-07-21 15:04:37 WARN Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_path= is deprecated. Use Selenium::WebDriver::Chrome::Service#driver_path= instead.
F
Failures:
1) Employee should have many :employee_projects
Failure/Error: it {expect(Employee).to have_many(:employee_projects)}
expected Employee to respond to `has_many?`
# ./spec/models/employee_spec.rb:5:in `block (2 levels) in <top (required)>'
Finished in 0.00687 seconds (files took 1.21 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/models/employee_spec.rb:5 # Employee should have many :employee_projects
[15:04:37] (rev2) Esto
// ♥ rpsec
bash: rpsec: command not found
[15:25:58] (rev2) Esto
// ♥ rspec
2019-07-21 15:26:02 WARN Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_path= is deprecated. Use Selenium::WebDriver::Chrome::Service#driver_path= instead.
FF
Failures:
1) Employee ActiveRecord Association tests
Failure/Error: it { expect(employee).to have_many(:employee_projects) }
NameError:
undefined local variable or method `employee' for #<RSpec::ExampleGroups::Employee::ActiveRecordAssociationTests:0x00007fc28c60c470>
# ./spec/models/employee_spec.rb:6:in `block (3 levels) in <top (required)>'
2) Employee ActiveRecord Association tests
Failure/Error: it { expect(employee).to have_many(:projects).through(:employee_projects)}
NameError:
undefined local variable or method `employee' for #<RSpec::ExampleGroups::Employee::ActiveRecordAssociationTests:0x00007fc28c614f80>
# ./spec/models/employee_spec.rb:7:in `block (3 levels) in <top (required)>'
Finished in 0.00482 seconds (files took 1.11 seconds to load)
2 examples, 2 failures
Failed examples:
rspec ./spec/models/employee_spec.rb:6 # Employee ActiveRecord Association tests
rspec ./spec/models/employee_spec.rb:7 # Employee ActiveRecord Association tests
Here is my User
model:
class Employee < ApplicationRecord
has_many :employee_projects
has_many :projects, through: :employee_projects
end
and here is my rspec test:
require 'rails_helper'
RSpec.describe Employee, type: :model do
describe 'ActiveRecord Association tests' do
it { expect(employee).to have_many(:employee_projects) }
it { expect(employee).to have_many(:projects).through(:employee_projects)}
end
end
and my Gem file looks like this:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.3'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'rspec', '~> 3.0'
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
gem 'activerecord-import'
gem 'phonelib'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
gem 'webdrivers', '~> 3.0'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
# gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem "rspec-rails", :group => [:development, :test]
Do I have rspec installed correctly? Not sure about what I'm doing wrong.
Aucun commentaire:
Enregistrer un commentaire