0

我在不同的标题下发布了这个请求,在我用信息更新请求后没有收到任何反馈。

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

我正在从事一个私人项目,我是一个学习 Rails 并尝试使用 TDD/BDD 做正确的事情的开发人员,但我不得不说的这种经验让我想放弃测试,因为我根本没有花时间尝试解决环境问题。

我现在花了 24 小时的大部分时间试图解决这个问题。这些是我尝试过的事情:

  1. 删除 Gemfile.lock 并重新安装包
  2. 删除 gemset 并从头开始
  3. 按照教程(M.Hartl 从头开始​​)重建我的部分环境

昨晚,当我从本地项目切换到开始更新 git 版本的一些功能时,--drb 选项失败了(因为我还是新手,所以我正在运行两个项目和两个 git 文件夹)。

我 [ open_and_save_page] 在本地项目中工作,但是当我在开始下一阶段交付之前运行我的规范以测试一切都很好时,我遇到了与 --drb 相关的失败,所以我升级了,当我转身时,这似乎消失了的守护进程。

这是当前的错误:

imac:Genie railsdev$ rspec spec/requests/authentication_pages_spec.rb --drb
No DRb server is running. Running in local process instead ...
/Users/railsdev/Development/railsprojects/Genie/Genie/spec/requests/authentication_pages_spec.rb:47:in `block (3 levels) in <top (required)>': undefined local variable or method `save_and_open_page' for #<Class:0x007ff51d35a8a8> (NameError)
    from /Users/railsdev/.rvm/gems/ruby-1.9.3-p125@genie-bb-v3-3/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval'
    from /Users/railsdev/.rvm/gems/ruby-1.9.3-p125@genie-bb-v3-3/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `subclass'
    from /Users/railsdev/.rvm/gems/ruby-1.9.3-p125@genie-bb-v3-3/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in `describe'
    from /Users/railsdev/Development/railsprojects/Genie/Genie/spec/requests/authentication_pages_spec.rb:39:in `block (2 levels) in <top (required)>'
    from /Users/railsdev/.rvm/gems/ruby-1.9.3-p125@genie-bb-v3-3/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval'
    from /Users/railsdev/.rvm/gems/ruby-1.9.3-p125@genie-bb-v3-3/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `subclass'
    from /Users/railsdev/.rvm/gems/ruby-1.9.3-p125@genie-bb-v3-3/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in `describe'
    from /Users/railsdev/Development/railsprojects/Genie/Genie/spec/requests/authentication_pages_spec.rb:24:in `block in <top (required)>'
    from /Users/railsdev/.rvm/gems/ruby-1.9.3-p125@genie-bb-v3-3/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval'
    from /Users/railsdev/.rvm/gems/ruby-1.9.3-p125@genie-bb-v3-3/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `subclass'
    from /Users/railsdev/.rvm/gems/ruby-1.9.3-p125@genie-bb-v3-3/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in `describe'
    from /Users/railsdev/.rvm/gems/ruby-1.9.3-p125@genie-bb-v3-3/gems/rspec-core-2.11.1/lib/rspec/core/dsl.rb:18:in `describe'
    from /Users/railsdev/Development/railsprojects/Genie/Genie/spec/requests/authentication_pages_spec.rb:13:in `<top (required)>'
    from /Users/railsdev/.rvm/gems/ruby-1.9.3-p125@genie-bb-v3-3/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load'
    from /Users/railsdev/.rvm/gems/ruby-1.9.3-p125@genie-bb-v3-3/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
    from /Users/railsdev/.rvm/gems/ruby-1.9.3-p125@genie-bb-v3-3/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `map'
    from /Users/railsdev/.rvm/gems/ruby-1.9.3-p125@genie-bb-v3-3/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
    from /Users/railsdev/.rvm/gems/ruby-1.9.3-p125@genie-bb-v3-3/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in `run'
    from /Users/railsdev/.rvm/gems/ruby-1.9.3-p125@genie-bb-v3-3/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:66:in `rescue in run'
    from /Users/railsdev/.rvm/gems/ruby-1.9.3-p125@genie-bb-v3-3/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:62:in `run'
    from /Users/railsdev/.rvm/gems/ruby-1.9.3-p125@genie-bb-v3-3/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'
imac:Genie railsdev$ 

这是我的 Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.8'

# 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.11.0"
  gem 'guard-rspec', '~> 1.2.1'
  gem 'annotate', '~> 2.4.1.beta'
  gem 'pickle'
  gem 'launchy'
  gem 'simplecov'
  gem 'pg', '0.12.2'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.5'
  gem 'coffee-rails', '~> 3.2.2'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platform => :ruby

  gem 'uglifier', '>= 1.2.3'
  gem 'bootstrap-sass', '~> 2.0.3.1'
end

gem 'jquery-rails', '2.0.2'
gem 'bootstrap-will_paginate', '0.0.5'
gem 'bootstrap-datepicker-rails', :require => 'bootstrap-datepicker-rails'#,
                              #:git => 'git://bitbucket.org/railyboy/bootstrap-datepicker-rails.git' 
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'

# Test gems on Macintosh OS X
group :test do
  gem 'capybara', '1.1.2'
#  gem 'rb-fsevent', '0.4.3.1', :require => false
  # gem 'rb-fsevent', :git => 'git://github.com/ttilley/rb-fsevent.git', :branch => 'pre-compiled-gem-one-off'
gem 'rb-fsevent', '~> 0.9.1', :require => false
  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

.rvmrc 文件

rvm use ruby-1.9.3-p125@genie-bb-v3-3 --create

which rvm => /Users/railsdev/.rvm/bin/rvm

rvm -v => rvm 1.16.8 (master) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]

保护文件:

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

require 'active_support/core_ext'

guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
  watch('config/application.rb')
  watch('config/environment.rb')
  watch(%r{^config/environments/.+\.rb$})
  watch(%r{^config/initializers/.+\.rb$})
  watch('Gemfile')
  watch('Gemfile.lock')
  watch('spec/spec_helper.rb')
  watch('test/test_helper.rb')
  watch('spec/support/')
end

guard 'rspec', :version => 2, :all_after_pass => false, :cli => '--drb' do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }  
  watch('spec/spec_helper.rb') { "spec" }

  # Rails example
  watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
  watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
  watch('spec/spec_helper.rb') { "spec" }  
  watch('config/routes.rb') { "spec/routing" }
  watch('app/controllers/application_controller.rb') { "spec/controllers" }
  # Capybara request specs 
  watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$}) do |m|
    ["spec/routing/#{m[1]}_routing_spec.rb",
     "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
     "spec/acceptance/#{m[1]}_spec.rb",
     "spec/requests/#{m[1].singularize}_pages_spec.rb",
     (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" :
                       "spec/requests/#{m[1].singularize}_pages_spec.rb")]
  end
  watch(%r{^app/views/(.+)/}) do |m|
    "spec/requests/#{m[1].singularize}_pages_spec.rb"
  end

  # Turnip features and steps
  watch(%r{^spec/acceptance/(.+)\.feature$})
  watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$})   { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }

end

spec_helper.rb 文件:

require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'

Spork.prefork do
  # Loading more in this block will cause your tests to run faster. However,
  # if you change any configuration or code from libraries loaded here, you'll
  # need to restart spork for it take effect.

  # This file is copied to spec/ when you run 'rails generate rspec:install'
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'

  # Requires supporting ruby files with custom matchers and macros, etc,
  # in spec/support/ and its subdirectories.
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

  RSpec.configure do |config|
    # ## Mock Framework
    #
    # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
    #
    # config.mock_with :mocha
    # config.mock_with :flexmock
    # config.mock_with :rr
    config.mock_with :rspec

    # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
    config.fixture_path = "#{::Rails.root}/spec/fixtures"

    # If you're not using ActiveRecord, or you'd prefer not to run each of your
    # examples within a transaction, remove the following line or assign false
    # instead of true.
    config.use_transactional_fixtures = true

    # If true, the base class of anonymous controllers will be inferred
    # automatically. This will be the default behavior in future versions of
    # rspec-rails.
    config.infer_base_class_for_anonymous_controllers = false

    # Run specs in random order to surface order dependencies. If you find an
    # order dependency and want to debug it, you can fix the order by providing
    # the seed, which is printed after each run.
    #     --seed 1234
    config.order = "random"
  end



end

Spork.each_run do
  # This code will be run each time you run your specs.

end

并且 [ save_and_open_page] 被调用的文件:

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') }

      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) }
      save_and_open_page
      # it { should have_content("[#{current_user}]") }

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

...
end

我不确定我是否以正确的方式发布我的问题,因为在其他一些问题上我没有任何回应。这一切仍然是新的,这里的帮助是巨大的。所以提前谢谢。

我需要做些什么才能让它在第二个项目中发挥作用?

我确实注意到的一件事是,自从我开始将 [ use] 放入 .rvmrc 文件时,当我 cd 进入目录时,我得到以下内容。

Using /Users/railsdev/.rvm/gems/ruby-1.9.3-p125 with gemset genie-bb-v3-3
Running /Users/railsdev/.rvm/hooks/after_cd_bundler 

[ open_and_save_page] 是水豚方法吗?launchy 在哪里适合所有这些?我认为这是与黄瓜相关的宝石。

4

1 回答 1

3

我相信这是一个新的用户理解错误。我发现如果我将 [ save_and_open_page] 放在一个it块中,我可以让它工作。

我在阅读的任何文件中都没有看到这一点,但我想这是有道理的。

于 2012-10-06T17:54:17.900 回答