我想用rspec for RoR对一个方法进行单元测试,并有一个如下所示的方法:
def create_record(obj, params)
begin
obj.add_attributes(params)
result = obj.save
rescue
MyMailer.failed_upload(@other_var, obj.api_class_name, params).deliver_now
end
end
create_record永远不会直接调用,而是通过另一种适当填充@other_var的方法来调用。
我应该如何测
我目前正在尝试运行sinatra框架,该框架从代码库下载代码,对代码执行RSpec,然后处理来自rspec的结果。然而,当我从不同的应用程序调用rspec时,我遇到了运行它的问题。
我一直收到以下错误:
/Users/dir/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler/rubygems_integration.rb:147:in `block in replace_gem': rspec-core is not part of the bundle. Add it to Gemfile. (Gem::L
在我的上传文件的rspec中,我存根了一个函数,如下所示:
allow(ABCCLass::XYZProcessor).to receive(:prepare_processing).with(csv_statements).and_return(nil)
和
let(:csv_statements) do
[fixture_file_upload('transaction.csv', 'application/csv')]
end
I get error in expect: expect Rack::Test::UploadedFile get Acti
我正在尝试使用 gem对我的rspec测试进行存根编辑。我的rspec配置如下所示:
RSpec.configure do |config|
# ... various rspec config options ...
config.before(:each) do
redis_instance = MockRedis.new
Redis.stub(:new).and_return(redis_instance)
Redis::Store.stub(:new).and_return(redis_instance)
end
end
不幸的是,我仍然看到get
我有下面的rspec测试,我正在尝试在它里面存根api方法。我在FactoryGirl的特征中定义存根,并使用after(:build)回调。
describe '#get_json_from_api' do
let(:output_file) { video_file.json_path }
context "when api works" do
around(:each) do |rspec_test|
File.delete(output_file) if File.exists?(output_file)
我们有一个RoR应用程序,Rspec,用于使用Webmock测试HTTP请求。在不得不在我们的遗留代码库中进行一些重构之后,我意识到我们的许多测试都有不必要的存根。像这个例子一样,do_a函数已经被重构,所以我们不需要做任何api调用,所以stub_request不再是必需的,更糟糕的是,它应该被删除。
it 'does something' do
stub_request(:get, 'http://something.com/users/123')
do_a
expect(..)
end
解决此
我有一个Rails 4应用程序,下面是我的lib/foobar:
jan@rmbp ~/D/r/v/l/foobar> tree
.
├── foo_bar.rb
└── foobar_spec.rb
0 directories, 2 files
和档案:
foobar_spec.rb
require "spec_helper"
describe "FooBar" do
subject { FooBar.new }
its(:foo) { should == "foo"}
#stubbed version of test c
我有一个非常奇怪的问题: Sidekiq试图在测试环境中建立与Redis的连接。我在rails 4.1.4和ruby 2.1.2中使用了sidekiq 3.2.2和rspec-sidekiq 2.0.0.beta。
这是我的测试
require 'rails_helper'
describe FetchWorker::FetchWorker do
it 'runs in fetch queue' do
expect(subject).to be_processed_in :fetch
end
it 'not retry when it fa
describe SomeThing do
before :all do
# ...
FooClass.stub(:fooMethod).with('a').and_return("something")
end
end
和rspec 1一起工作很酷。
我已经更新到rspec 2,这是我现在收到的这行代码:
Failure/Error:
FooClass.stub(:fooMethod).with('a').and_return("something")
NoMethodError:
我正在开发一个示例RoR应用程序,但在使用rspec进行测试时遇到了问题。我已经安装了rspec并运行了测试,但是它们失败了,我不知道为什么。我运行以下命令:
bundle exec rspec spec/
当我运行这段代码时,我得到的错误信息是:
Failures:
1) PagesController GET 'home' should be successful
Failure/Error: Unable to find matching line from backtrace
NameError:
uninitialized co
我在Ubuntu11.10上运行RubyMine 4,RubyMine内部一切都很好,我可以运行服务器,开发等等。但是,当我需要在命令行上工作时,我什么也做不了..
我光盘到我的应用程序目录,然后我试图:
$ rails s
我得到:
The program 'rails' is currently not installed. You can install it by typing:
sudo apt-get install rails
这是很奇怪的,为什么它没有安装,而我可以正常工作在RubyMine IDE!
我需要使用命令行卸载一个gem,以发现我不能按它应该使用的
我编写了一个映射器,它与从facebook获得的属性相匹配,并将它们设置为我的模型。
class Mapper::FacebookUser
def initialize (user, facebook_user)
@user = user
@facebook_user = facebook_user
end
def name
@user.name = @facebook_user['name'] if @facebook_user['name'] rescue false
end
end
Facebook的回应是这样的
嗨,我正在尝试rspec嘲笑下面的课程:
class Person
def initialize(personid)
Rails.logger.debug "Creating person with id #{personid}"
end
end
使用此方法:
require 'spec_helper'
describe Person do
describe "#initialize" do
let(:rails_mock) { double("Rails
在我的Ruby (不是Rails)程序中,我在顶级模块中创建了全局变量。这些全局变量被设置为外部服务的客户端,因此我的程序在设置它们时进行API调用。我正在尝试弄清楚如何在RSpec中正确地存根这些应用程序接口调用。
我想在顶层模块中测试一个类,它看起来或多或少如下所示。Worker不会直接调用类中任何位置的全局变量。
module TopModule
class Worker
end
end
下面是TopModule:
module TopModule
# (As an aside, the external service is AWS)
$client = Externa
我正在学习如何使用。
我是专门的功能。
我将与和结合使用。
我遇到过
var Redis = require("ioredis");
var redis = new Redis();
var pub = new Redis();
redis.subscribe("news", "music", function(err, count) {
// Now we are subscribed to both the 'news' and 'music' channels.
// `count` represen