您好我在spec / myprocess中创建了一个测试用例,如下所示
before :each do
@my_base = MyBase.new
end
describe "new_my_base" do
it "should not take any arguments and retuens a MyBase object" do
@my_base.should be_an_instance_of MyBase
end
end
describe "#my_path" do
it "returns the correct mybase file path" do
$path.should eql App::Application.config.my_encode_type.to_s
end
end
当我调试rspec spec / lib / mybasetest.rb时,它会抛出以下错误。
kalanamith@kalanamith:~/Documents/projects/leena$ rspec spec/lib/mybasetest.rb
*** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`.
/var/lib/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require': iconv will be deprecated in the future, use String#encode instead.
*** Mocha deprecation warning: `require 'mocha/standalone'` has been deprecated. Please use `require 'mocha/api' instead.
/var/lib/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- mocha/object (LoadError)
/home/kalanamith/Documents/projects/fakturabank/spec/lib/mybasetest.rb:4:in `<top (required)>': undefined method `before' for main:Object (NoMethodError)
from /var/lib/gems/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `load'
from /var/lib/gems/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `block in load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `map'
from /var/lib/gems/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:22:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:69:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:10:in `block in autorun'
这是我的宝石文件
source 'https://rubygems.org'
gem 'rails', '3.2.13'
gem 'jquery-rails' , '3.0.0'
gem 'pg'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
group :development, :test do
gem 'rails-dev-tweaks', '~> 0.6.1'
gem 'debugger'
gem 'rspec-rails', '2.10.0'
gem 'annotate'
gem 'factory_girl_rails'
gem 'shoulda-matchers'
gem 'simplecov', :require => false
gem 'simplecov-rcov', :require => false
gem 'pry'
gem "guard-rspec"
end
group :test do
gem 'mocha'
end
group :test do
gem "webmock"
end
gem 'debugger' # This gem works with ruby 1.9.3 it wraps these other things
gem 'savon', "~> 1.2.0"
gem 'airbrake'
gem 'aasm'
gem 'paranoia'
gem 'acts_as_tree'
gem 'will_paginate'
gem 'translate-rails3'
gem 'wicked_pdf'
gem 'activemerchant'
gem 'libxml-ruby'
gem 'libxslt-ruby'
gem 'ruby-xslt'
gem 'exception_notification', :require => 'exception_notifier'
gem "uuidtools", "~> 2.1.3"
gem "ruby-filemagic"
gem "rmagick", :require => false
gem "rubyzip"
gem "spreadsheet"
gem "multi_json"
gem "multi_xml"
gem "httparty"
#FormBuilder backwards compatibility
gem "dynamic_form"
gem "prototype-rails"
gem "formtastic"
gem "net-ssh"
gem "net-scp"
对于rails来说这是一个新手,这是我第一次使用rspec框架。如果有人能帮助我,我将不胜感激。提前谢谢
答案 0 :(得分:3)
之前必须有一个“ describe ”:每个都
describe "Bla bla" do
before :each do
@my_base = MyBase.new
end
etc...
end
无论如何,文件名应以_spec.rb
为后缀答案 1 :(得分:1)
before
块应位于describe
方法
答案 2 :(得分:0)
如果您正在使用RSpec,则文件末尾必须以_spec.rb
示例:my_base_spec.rb
要运行:bundle exec rspec spec/my_base_spec.rb
或只是bundle exec rspec