ruby on rails tutorial section 3.2 rspec testing error
It seems you are using old version of gem. Try 'selenium-webdriver', '~> 2.35.1'
latest
Error in testing ruby on rails using rspec in tutorial
Since you're using Bundler (i.e. you have a Gemfile
), you need to make sure Capybara is in there too, otherwise your rails app won't know the gem is installed. Update your Gemfile
to include capybara in the development/test environments:
group :development, :test do
gem 'rspec-rails', ">= 2.0.0.beta"
gem 'capybara'
end
Ruby on Rails , Rspec Error while testing
You need to require 'spec_helper'
in your spec source.
Your spec_helper
should include both rspec/rails
and capybara/rails
in it.
You'll want to use get
instead of visit
if you want to access the response, however.
RSpec test destroy method (Rails Tutorial 3.2 Ch. 9, Ex. 10)
You are confusing rspec-rails request specs which are integration tests and are executed in a simulated browser and controller specs which test controller in isolation. delete(action, *args)
(and get
, post
and so on) - is a method simulating request from ActionController::TestCase, so it's not available in your test.
So your only option is to simulate a click in a browser. I don't know how you hide your delete link, if the html is there but hidden you should be able to click it. If it's not there (removed on the server side when generating view) you can use capybara's page.execute_script
(but you have to enable javascript for this example :js => true
). You can either add the link back:
page.execute_script("$('body').append("<a href="/users/1" data-method="delete" rel="nofollow">Destroy</a>")")
or make ajax call:page.execute_script("$.ajax({type:'DELETE',url:'/users/1'})")
Didn't test but something like this should work. Error running rspec test in rails
There must be a "describe" that wraps before :each do
describe "Bla bla" do
before :each do
@my_base = MyBase.new
end
etc...
end
Anyway, the file name should be suffixed with _spec.rb What is wrong with this Rspec test
In your HAML, your title shouldn't be in between apostrophes. Try:
!!! Strict
%html{ :xmlns => "http://www.w3.org/1999/xhtml", 'xml:lang'=>"en", :lang=>"en" }
%head
%title Ruby on Rails | Home
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= csrf_meta_tags
%body
= yield
Also, make sure you include render_views
in your spec file:describe PagesController do
render_views
.
.
end
If that doesn't work. Try using a different gem version of Rspec - there is a bug in RSpec 2.0.0.beta.19group :development do
gem 'rspec-rails', '2.0.0.beta.18'
end
group :test do
gem 'rspec-rails', '2.0.0.beta.18'
gem 'spork', '0.8.4'
end
RSpec fails testing
you need to fix this
# PostgreSQL 8.4
development:
adapter: postgresql
encoding: unicode
database: ODQ_APP
pool: 5
and add test section like this# PostgreSQL 8.4
test:
adapter: postgresql
encoding: unicode
database: ODQ_APP_test
pool: 5
also remember to create test db :)Rspec runs in "test" environment so he will be looking under test key from database.yml not development :)
rspec test failure when switching from initializing attributes to Factory
The factory puts the record in the DB. User.new doesn't until it is saved. The original test doesn't check if user_with_same_email gets created, rather that 'it' (subject { @user }) can't be created because the email exists. After making your change to the @user, I had to rewrite the test:
describe "when email address is already taken" do
let (:user_with_same_email) { @user.dup }
specify { user_with_same_email.should_not be_valid }
end
Related Topics
Ruby 1.9 How to Convert Array to String Without Brackets
Error: Spawn Enoent: Missing The SASS Executable
How Do Erlang Actors Differ from Oop Objects
What's The Best Way to Test Delayed_Job Chains with Rspec
Many to Many Table with an Extra Column in Rails
How to Use Strong Parameters with an Objects Array in Rails
Using Google Search Rest API in Ruby
How to Implement Curry(Partial Function) in Ruby
Clean Install Osx 10.9.1 Returns "Undefined Method 'Path2Class'" When Trying to Install Gems
Is 'Respond_To_Missing''s Second Argument Useful for Anything
How to Print a Multi-Dimensional Array in Ruby
Ruby/Rails 3.1: Given a Url String, Remove Path
Why Do Ruby People Say They Don't Need Interfaces
Regex That Matches Valid Ruby Local Variable Names
How to Override a Variable in a Ruby Subclass Without Affecting The Superclass