2013-09-26 15 views
0

寶石文件水豚導致沒有錯誤的方法時,其方法是通過Rspec的引用

source 'https://rubygems.org' 

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 
gem 'rails', '4.0.0' 

# Use sqlite3 as the database for Active Record 
gem 'sqlite3' 

# Use SCSS for stylesheets 
gem 'sass-rails', '~> 4.0.0' 

# Use Uglifier as compressor for JavaScript assets 
gem 'uglifier', '>= 1.3.0' 

# Use CoffeeScript for .js.coffee assets and views 
gem 'coffee-rails', '~> 4.0.0' 

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

# Use jquery as the JavaScript library 
gem 'jquery-rails' 

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks 
gem 'turbolinks' 

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 
gem 'jbuilder', '~> 1.2' 

group :doc do 
    # bundle exec rake doc:rails generates the API under doc/api. 
    gem 'sdoc', require: false 
end 

# Use ActiveModel has_secure_password 
# gem 'bcrypt-ruby', '~> 3.0.0' 

# Use unicorn as the app server 
# gem 'unicorn' 

# Use Capistrano for deployment 
# gem 'capistrano', group: :development 

# Use debugger 
# gem 'debugger', group: [:development, :test] 

gem "factory_girl_rails" 

group :development, :test do 
    gem "rspec-rails", "~> 2.0" 
    gem "capybara", "~> 2.1.0" 
end 

spec_helper.rb

# 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' 
require 'capybara/rspec' 
require 'capybara/rails' 

# 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 } 

# Checks for pending migrations before tests are run. 
# If you are not using ActiveRecord, you can remove this line. 
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration) 

RSpec.configure do |config| 
    config.include Capybara::DSL 
    # ## 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 

    # 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 

xxtests_spec.rb

require 'spec_helper' 

describe "Xxtests" do 
    describe "GET /xxtests" do 
     it "works! (now write some real specs)" do 
     get 'people/new' 
     response.status.should be(200) 
     end 
     it "works! (now write some real specs)" do 
     get people_path 
     response.status.should be(200) 
     end 
    end 

    describe "POST /persons" do 
     # visit 'people/new' 
     response.status.should be(200) 
    end 
end 

所有作品都完美無缺。第二個我取消

visit 'people/new' 

我得到

undefined method error. 

我已經經歷了非常仔細地閱讀了水豚和RSpec文檔,我所做的一切。我真的不知道還有什麼要說的,但它不起作用。

回答

1

要調用visit一個describe塊內,而不是一個代碼示例(it塊)內。嘗試:

describe "POST /persons" do 
    it "responds with success status" do  
    visit 'people/new' 
    response.status.should be(200) 
    end 
end 

的水豚方法混合到的代碼示例實例,因此不提供外部。

相關問題