2014-09-03 65 views
0

如何在不respec單元測試實現gem shoulda?這是我的Gemfile文件:如何在沒有rspec的單元測試rails 4中阻止gem shoulda?

source 'https://rubygems.org' 


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

group :production do 
    # Use PostgreSQL as the database for Active Record on Heroku 
    gem 'pg' 
end 

group :development, :test do 
    # Use sqlite3 as the database for Active Record 
    gem 'sqlite3' 
    gem "minitest" 
    gem 'byebug' 
end 

# Use SCSS for stylesheets 
gem 'sass-rails', '~> 4.0.3' 
# 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', '~> 2.0' 
# bundle exec rake doc:rails generates the API under doc/api. 
gem 'sdoc', '~> 0.4.0',   group: :doc 

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 
gem 'spring',  group: :development 

# Use ActiveModel has_secure_password 
# gem 'bcrypt', '~> 3.1.7' 

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

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

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

gem 'devise' 
gem 'shoulda' 
gem 'omniauth-facebook' 
gem 'omniauth-google-oauth2' 

,這是我test_helper.rb中的文件:

ENV['RAILS_ENV'] ||= 'test' 
require File.expand_path('../../config/environment', __FILE__) 
require 'rails/test_help' 
include Devise::TestHelpers 
require 'minitest/autorun' 
require 'shoulda/rails' 

class ActiveSupport::TestCase 
    # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. 
    fixtures :all 

    # Add more helper methods to be used by all tests here... 
end 

這是我的榜樣模型試驗單位:

require 'test_helper' 

class UserTest < ActiveSupport::TestCase 
    should validate_presence_of(:name) 
    should validate_presence_of(:last_name) 
    should validate_presence_of(:id_number) 
    should ensure_inclusion_of(:id_issuing_country).in_array(["Spain"]) 
    should validate_presence_of(:birth_date) 
    should validate_presence_of(:email) 
    should validate_presence_of(:bank_account) 
end 

,當我在我的控制檯乳寧這樣的:bin/rake test test/models/user_test.rb

我得到的錯誤是這樣的:

LoadError: cannot load such file -- shoulda/rails 

回答

1

從應用程序中的寶石文件,我在

.... 
group :test do 
    # gem 'faker' 
    gem 'launchy' 
    gem 'relish' 
    gem 'selenium-webdriver', '~> 2.42.0' 
    gem 'capybara' 
    gem 'database_cleaner' 
    gem 'shoulda-matchers', '~>2.6.2' 
    gem 'shoulda' 
end 
.... 

希望這有助於工作 - 皮埃爾

+0

謝謝@ user1854802,解決我的問題: ) – tardjo 2014-09-03 06:02:12

相關問題