save_and_open_page(capybara / launchy)停止在项目中工作 - 错误

时间:2012-09-26 19:26:35

标签: ruby-on-rails-3.2 capybara rspec-rails

在合并Rails两个项目时,尝试调试一些我无法工作的规范。

我已经删除了我的Gemfile.lock并从头开始重新安装,我已经对特定的宝石进行了捆绑更新,而且整个很多但是当我尝试在我的请求规范中使用时出现错误

save_and_open_page

railsdev$ bin/rspec spec/requests/authentication_pages_spec.rb 
No DRb server is running. Running in local process instead ...
/Users/rb/Repos/Genie/spec/requests/authentication_pages_spec.rb:33:in `block (3 levels) in <top (required)>': undefined local variable or method `save_and_open_page' for #<Class:0x007f981d139608> (NameError)
    from /Users/rb/.rvm/gems/ruby-1.9.3-p125@genie/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:201:in `module_eval'
    from /Users/rb/.rvm/gems/ruby-1.9.3-p125@genie/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:201:in `subclass'
    from /Users/rb/.rvm/gems/ruby-1.9.3-p125@genie/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:187:in `describe'
    from /Users/rb/Repos/Genie/spec/requests/authentication_pages_spec.rb:27:in `block (2 levels) in <top (required)>'
    from /Users/rb/.rvm/gems/ruby-1.9.3-p125@genie/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:201:in `module_eval'
    from /Users/rb/.rvm/gems/ruby-1.9.3-p125@genie/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:201:in `subclass'
    from /Users/rb/.rvm/gems/ruby-1.9.3-p125@genie/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:187:in `describe'
    from /Users/rb/Repos/Genie/spec/requests/authentication_pages_spec.rb:24:in `block in <top (required)>'
    from /Users/rb/.rvm/gems/ruby-1.9.3-p125@genie/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:201:in `module_eval'
    from /Users/rb/.rvm/gems/ruby-1.9.3-p125@genie/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:201:in `subclass'
    from /Users/rb/.rvm/gems/ruby-1.9.3-p125@genie/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:187:in `describe'
    from /Users/rb/.rvm/gems/ruby-1.9.3-p125@genie/gems/rspec-core-2.10.1/lib/rspec/core/dsl.rb:18:in `describe'
    from /Users/rb/Repos/Genie/spec/requests/authentication_pages_spec.rb:13:in `<top (required)>'
    from /Users/rb/.rvm/gems/ruby-1.9.3-p125@genie/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `load'
    from /Users/rb/.rvm/gems/ruby-1.9.3-p125@genie/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `block in load_spec_files'
    from /Users/rb/.rvm/gems/ruby-1.9.3-p125@genie/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `map'
    from /Users/rb/.rvm/gems/ruby-1.9.3-p125@genie/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `load_spec_files'
    from /Users/rb/.rvm/gems/ruby-1.9.3-p125@genie/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:22:in `run'
    from /Users/rb/.rvm/gems/ruby-1.9.3-p125@genie/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:66:in `rescue in run'
    from /Users/rb/.rvm/gems/ruby-1.9.3-p125@genie/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:62:in `run'
    from /Users/rb/.rvm/gems/ruby-1.9.3-p125@genie/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:10:in `block in autorun'

任何人都可以建议为什么失败以及我需要做些什么来纠正这个问题?

我让它在一个测试项目中运行,但在核心项目的主副本中,我不想将其搞砸。

EDIT#1

所要求的代码:

require 'spec_helper'

# describe "AuthenticationPages" do
#   describe "GET /authentication_pages" do
#     it "works! (now write some real specs)" do
#       # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
#       get authentication_pages_index_path
#       response.status.should be(200)
#     end
#   end
# end

describe "Authentication" do

  subject { page }

  describe "login page" do
    before { visit login_path }

    it { should have_selector('h1',    text: 'Login') }
    it { should have_selector('title', text: 'Login') }
  end

  describe "login" do
    before { visit login_path }

    describe "with invalid information" do
      before { click_button "Login" }

      it { should have_selector('title', text: 'Login') }
      it { should have_error_message('Invalid') }

      save_and_open_page

      describe "after visiting another page" do
        before { click_link "Home" }
        it { should_not have_selector('div.alert.alert-error') }
      end
    end

    describe "with valid information" do
      let(:user) { FactoryGirl.create(:user) }
      before { valid_login(user) }

      it { should have_selector('title', text: user.name) }
      #it { should have_link('Profile', href: user_path(user)) }
      it { should have_link('Logout', href: logout_path) }
      it { should_not have_link('Login', href: login_path) }

      describe "followed by logout" do
        before { click_link "Logout" }
        it { should have_link('Login') }
      end
    end
  end

  describe "authorization" do

    describe "for non-logged-in users" do
      let(:user) { FactoryGirl.create(:user) }

      describe "when attempting to visit a protected page" do
        before do
          visit edit_user_path(user)
          fill_in "Name",    with: user.name
          fill_in "Password", with: user.password
          click_button "Login"
        end

        describe "after logging in" do

          it "should render the desired protected page" do
            page.should have_selector('title', text: 'Edit user')
          end
        end
      end

      describe "in the Users controller" do

        describe "visting the user index" do
            before { visit users_path }
            it { should have_selector('title', text: 'Login') }
        end

        describe "visiting the edit page" do
          before { visit edit_user_path(user) }
          it { should have_selector('title', text: 'Login') }
        end

        describe "submitting to the update action" do
          before { put user_path(user) }
          specify { response.should redirect_to(login_path) }
        end
      end
    end

    describe "as wrong user" do
      let(:user) { FactoryGirl.create(:user) }
      let(:wrong_user) { FactoryGirl.create(:user, name: "WrongName") }
      before { login user }

      describe "visiting Users#edit page" do
        before { visit edit_user_path(wrong_user) }
        it { should_not have_selector('title', text: full_title('Edit user')) }
      end

      describe "submitting a PUT request to the Users#update action" do
        before { put user_path(wrong_user) }
        specify { response.should redirect_to(root_path) }
      end
    end
  end
end

的Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.5'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

group :development, :test do
  gem 'sqlite3', '1.3.5'
  gem "rspec-rails", "~> 2.10.1"
  gem 'guard-rspec', '0.5.5'
  gem 'annotate', '~> 2.4.1.beta'
  gem 'pickle'
  gem 'simplecov'
  gem 'pg', '0.12.2'
  gem 'capybara', '1.1.2'
  gem 'launchy'   
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.4'
  gem 'coffee-rails', '~> 3.2.2'
  gem 'uglifier', '>= 1.2.3'
  gem 'bootstrap-sass', '~> 2.0.3.1'
  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platform => :ruby    
end

gem 'jquery-rails', '2.0.2'
gem 'bootstrap-will_paginate', '0.0.5'
gem 'bootstrap-datepicker-rails'
gem 'will_paginate', '3.0.3'
gem 'faker', '1.0.1'
gem 'wicked_pdf'

# To use ActiveModel has_secure_password
gem 'bcrypt-ruby', '3.0.1'

#gem 'ransack'
gem 'cancan'

# Test gems on Macintosh OS X
group :test do    
  gem 'rb-fsevent', :git => 'git://github.com/ttilley/rb-fsevent.git', :branch => 'pre-compiled-gem-one-off'
  gem 'growl', '1.0.3'
  gem 'guard-spork', '0.3.2'
  gem 'spork', '0.9.0'
  gem 'factory_girl_rails', '4.1.0'
  gem 'cucumber-rails', '1.2.1', :require => false
  gem 'database_cleaner', '0.7.0'
end 

group :production do
    gem 'pg', '0.12.2'
end

1 个答案:

答案 0 :(得分:9)

尝试从 it 块中调用save_and_open_page

所以而不是:

it { should have_error_message('Invalid') }

save_and_open_page

试试这个:

it { should have_error_message('Invalid'); save_and_open_page }

今晚为我修好了