我通过创建一个扩展到库类的子类来扩展现有的库。在子类中,我能够测试initialize方法中的大部分功能,但无法模拟super调用。子类如下所示。classChild如何编写rspec测试(使用mocha)以便我可以模拟super调用?请注意,我正在测试Child类中的initialize方法的功能。当提供额外参数时,我是否必须创建不调用super的单独代码路径? 最佳答案 你不能模拟super,你也不应该。当您模拟某些内容时,您正在验证是否收到了特定消息,而super不是一条消息——它是一个关键字。相反,弄清楚如果缺少super调
我想做的是在命令行上运行rubysayhello.rb,然后接收HellofromRspec。我已经明白了:classHellodefspeakputs'HellofromRSpec'endendhi=Hello.new#bringsmyobjectintoexistencehi.speak现在我想在rspec中编写一个测试来检查命令行输出实际上是“HellofromRSpec”而不是“我喜欢Unix”不工作。我目前在我的sayhello_spec.rb文件中有这个require_relative'sayhello.rb'#pointstofilesoIcan'see'itdescri
我有一个模型方法,它在执行时返回以下内容。{"data"=>[{"product"=>"PRODUCTA","orders"=>3,"ordered"=>6,"revenue"=>600.0},{"product"=>"PRODUCTB","orders"=>1,"ordered"=>5,"revenue"=>100.0}]}我想测试以确保第一个哈希中的“收入”存在,然后测试该值是否等于600。subject{described_class.order_items_by_revenue}it"includesrevenuekey"doexpect(subject).toinclude(
我编写了一个简单的类方法Buy.get_days(string),并尝试使用不同的文本字符串输入对其进行测试。但是我觉得它非常冗长。是否有更简洁的方法来测试以下内容?有没有相当于subjectformethods我可以继续传递输入不同的参数并检查结果?有没有办法避免在每个它处进行不必要的描述?谢谢describeBuydodescribe'.get_days'doit'shouldgetdays'doBuy.get_days('Includesa1-weeknightstayforupto4people').should==1endit'shouldgetdays'doBuy.get_
这是我的rspec文件:require'spec_helper'describe"Birds"dobefore{visitbirds_path}it"shouldhavetherighttitle"doexpect(page).tohave_content("ApprovedBirds")endit"shouldcontainthebird'sname,genus,species"dolet(:bird){FactoryGirl.create(:bird)}expect(page).tohave_content("#{bird.name}")expect(page).tohave_co
我在我的Rakefile中定义了以下RSpec(1.3.0)任务:require'spec/rake/spectask'Spec::Rake::SpecTask.new(:spec)do|spec|spec.libs我在spec/spec_helper.rb中有以下内容:require'rubygems'require'spec'require'spec/autorun'require'rack/test'require'webmock/rspec'includeRack::Test::MethodsincludeWebMockrequire'omniauth/core'我在spec/
如何使用RSpec指定#initialize行为?例如这里:generator.rbclassGeneratorattr_accessor:seeddefinitialize(seed=nil)@seed=seed||pick_seedenddefpick_seedTime.now.to_iendendgenerator_spec.rbrequire'generator'describeGeneratorit"calls'pick_seed'methodunlessseedspecified"doendend我想设置从#initialize方法调用的pick_seed方法的期望值。
我有一个使用强参数的标准RESTfulController。classUsersController在我的config/initializers中,我有文件strong_parameters.rbActiveRecord::Base.send(:include,ActiveModel::ForbiddenAttributesProtection)当我向CanCan的load_and_authorize_resource添加一个简单的调用时,我得到了1)UsersControllerPOSTcreatewithinvalidparamsre-rendersthe'new'template
我想要一份关于正在运行的测试的打印精美的摘要,类似于rspec--color--formatdoc可以minitest这样做吗? 最佳答案 "HowtocolorunittestswithlibminitestorTest:Unit?是一个类似的问题。那里提供了几个选项:骄傲turnpurdytestminitest-reporters 关于ruby-minitest可以做类似"rspec--color--formatdoc"的事情吗?,我们在StackOverflow上找到一个类似的问
我的模型有default_scope(:order=>'created_at')我的测试(rspec、factorygirl、shoulda等)是:require'spec/spec_helper.rb'describeCatMembershipdocontext"isvalid"dosubject{Factory.build(:cat_membership)}it{shouldbe_valid}it{shouldbelong_to:cat}it{shouldbelong_to:cat_group}it{shouldhave_db_column(:start_date)}it{shou