Long post but prolly simple if you understand Rails, RSpec &
differences between webrat & capybara.

I'm hoping someone can take a few moments to help me get a better
understanding of my environment. I have a somewhat intermediate
understanding of Ruby/Rails but a beginner's understanding of RSpec. I
have purchased The RSpec Book and, though helpful, leaves me with more
questions...probably from the very beginning I missed some basic
points...as just understanding HOW the environment is set up, WHERE/
WHY it looks for files to test and WHAT matchers, etc. are available
in tests is confusing me.

Anyway, in trying to wrap my head around RSpec I created a simple
Rails3 project. Altered the Gemfile to:

group :development, :test do
  gem 'rspec-rails'
  gem 'webrat'
  gem 'haml-rails'
  gem 'sass'
  gem 'spork', '~> 0.9.0.rc'
end

group :test do
  gem 'rspec'
end

Generated some scaffolding and starting making and editing some
specs... I was happy!

Now, after some stability and growing confidence I decided I'd try to
swap out webrat and replace it with capybara (which I've heard good
things about especially when dealing with javascript tests). So I
commented out "# gem 'webrat'" and
- added:

  gem 'capybara', :git => 'git://github.com/jnicklas/capybara.git'
  gem 'launchy'
  gem 'database_cleaner'

- added/modified what seems like alot of requires to spec_helper.rb
(spork, rubygems, rspec/rails, capybara/rspec, capybara/rails,
database_cleaner).

- changed some of my matchers from, what I think came from, webrat to,
what I think works with, Capybara...but I'm getting failures in my
controller & view specs. I'd really love to understand WHY and HOW/
WHERE to look so in the future I can diagnose these errors myself.

VIEW SPEC:

# spec/view/pages/about.html.haml_spec.rb
require 'spec_helper'

describe "pages/about.html.haml" do
 it "should have the right heading" do
   # render                                    # <- worked with webrat
   # rendered.should have_selector("h2", :content => "About Us")
   visit pages_about_path
   page.should have_selector('h2')
 end
end

Failures:

pages/about.html.haml should have the right heading
    Failure/Error: visit pages_about_path
    NoMethodError:
      undefined method `visit' for
#<RSpec::Core::ExampleGroup::Nested_7:0x0000010320a568>

CONTROLLER SPEC:

# spec/controllers/pages_controller_spec.rb
require 'spec_helper'

describe PagesController do

  describe "GET 'about'" do
    it "should be successful" do
      # get 'about'                      # <- worked with webrat
      # response.should be_success   #  <- webrat ok
      visit pages_about_path
      # visit '/pages/about.html'  #  <- also fails w/capybara
      page.should have_content('About Us')
      # page.html.should match(/About/i)  # no help
      # page.should match(/About/i)   # no help
    end
end


Failures:

  1) PagesController GET 'about' should be successful
     Failure/Error: visit pages_about_path
     LoadError:
       no such file to load -- action_controller/integration
     # ./spec/controllers/pages_controller_spec.rb:10:in `block (3
levels) in <top (required)>'

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to