Reputation: 3231
So i'm pretty new to rspec, i've used Cucumber in the past with Capybara but im trying to move more towards ACTUAL rspec with Capybara as opposed to Cucumber (I have no need for the BDD gherkin language in Cucumber)
My folder structure right now is spec/test_helper and spec/features/google_test.rb (just a sample for right now)
My gemfile has included:
gem 'capybara'
gem 'poltergeist'
gem 'selenium-webdriver'
gem 'rpsec'
my test_helper.rb file (In the project/spec folder)
#test_helper.rb
#Load up Capybara
require 'rspec'
require 'capybara/rspec'
require 'capybara'
require 'capybara/dsl'
#Load up Poltergeist
require 'capybara/poltergeist'
#Set JS Supported Driver
Capybara.javascript_driver = :poltergeist
my google_test.rb (In spec/features)
require 'test_helper'
Capybara.current_driver = :selenium
Capybara.run_server = false
Capybara.app_host = 'www.google.com'
describe "Visit Google Home Page", :type => feature do
it 'Google' do
visit ('/')
end
end
Running rspec spec/features/google_test.rb
I get:
Failures:
1) Visit Google Home Page Google Failure/Error: visit ('/') NoMethodError: undefined method
visit' for #<RSpec::ExampleGroups::VisitGoogleHomePage:0x007f8ef546ad30> # ./spec/features/google_test.rb:9:in
block (2 levels) in 'Finished in 0.00044 seconds (files took 0.47304 seconds to load) 1 example, 1 failure
Failed examples:
rspec ./spec/features/google_test.rb:8 # Visit Google Home Page Google
Any ideas?
Upvotes: 0
Views: 1206
Reputation: 49950
When you require capybara/rspec it configures RSpec to include the capybara DSL into tests of type :feature. There are a couple of ways to set the type on an RSpec test
describe "xyz", :type => :feature do # note :feature is a symbol
# test goes here
end
feature "xyz" do # alias that automatically sets the type
# tests go here
end
or by configuring RSpec to set the type based on directory name - https://www.relishapp.com/rspec/rspec-rails/docs/directory-structure
RSpec.configure do |config|
config.infer_spec_type_from_file_location!
end
Make sure you've used one of these methods and visit
should then be available
Upvotes: 1