草庐IT

bool_test

全部标签

ruby - 如何使用 lib minitest 或 Test :Unit? 为单元测试着色

我想在我的开发环境中进行单元测试输出颜色。但是,我无法让它在Linux(Debian和Ubuntu)上运行。当我包含以下库时:require'minitest/autorun'require'minitest/unit'require'minitest/pride'我得到:/usr/local/rvm/gems/ruby-1.9.2-p136/gems/minitest-2.3.1/lib/minitest/pride.rb:35:in`':undefinedmethod`output'forMiniTest::Unit:Class(NoMethodError)由代码引起:MiniTe

ruby - 在 Ruby 中评估许多 bool 表达式,如 Array#join

在Ruby中,您可以使用Array#join使用可选的分隔符简单地将多个字符串连接在一起。["a","b","c"].join#=>"abc"["a","b","c"].join("-")#=>"a-b-c"我想知道是否有很好的语法糖可以用一堆bool表达式做类似的事情。例如,我需要将一堆表达式&&放在一起。但是,将使用哪些表达式由用户输入决定。所以与其做一堆cumulative_value&&=expression[:a]ifuser[:input][:a]我想先根据输入收集所有的表达式,然后&&一举将它们全部收集起来。像这样的东西:be1=x>ybe2=Proc.new{|stri

ruby-on-rails - 使用 Rspec 和 Rack::Test 测试 REST-API 响应

我有点难过。我有以下集成测试:require"spec_helper"describe"/foods",:type=>:apidoincludeRack::Test::Methodslet(:current_user){create_user!}let(:host){"http://www.example.com"}beforedologin(current_user)@food=FactoryGirl.create_list(:food,10,:user=>current_user)endcontext"viewingallfoodsownedbyuser"doit"asJSON"d

Ruby bool 双重否定约定

谁能告诉我为什么很多Rubybool方法使用这种双重否定约定?!!(booleanexpression) 最佳答案 双重否定确保无论初始值如何,您将始终得到true或false,绝不会是神秘值。这很方便,因为它避免了对您不再需要的对象的悬垂引用,或者必须区分两种类型的假值,nil和false。经常你会看到这样写的方法:deflogged_in?!!@session_userend这将返回true或false并且该值可用于任何需要的目的。将其与此进行比较:deflogged_in?@session_userend在这种情况下,如果您保

ruby - 获取名称错误 : `format' is not allowed as an instance variable name when testing instance variable with rspec

我有以下测试:let(:client){Descat::Client.new}describe'poblacio'doit'shouldsetformatcorrectly'doclient.poblacio('v1','json','dades')expect(client.instance_variable_get(:format)).toeq('json')endend我有以下正在测试的代码:moduleDescatclassClientBASE_URL='http://api.idescat.cat/'definitialize(attributes={})attributes

ruby-on-rails - 使用 Test::Unit 和 Shoulda 设置 Factory Girl

我正在尝试在RubyonRails中使用Test::Unit和Shoulda设置FactoryGirl。我已经安装了gem,在test/factories目录下创建了我的工厂文件,并在test/models目录下创建了我的spec文件。我得到的当前错误是“ArgumentError:没有这样的工厂:测试”,这让我相信没有加载test_factory.rb文件?关于我应该更改什么有任何想法吗?这是我的文件。#test/factories/test_factory.rbFactory.define:testdo|t|t.name'test_spotlight't.label'testspo

ruby - Test::Unit 是否仍然与 Rails 相关?

我正在以古老的方式学习Rails。以阅读AgileWebDevelopmentwithRails(第3版)作为起点。我目前在教测试的章节中。我也知道其他BDD测试框架,例如RSPec。所以我想知道RSpec、Cucumber、Shoulda等框架是否可以取代了解/使用Test::Unit的需要?它们本身是否相关并用于不同的目的?更新:由于我是测试新手,我也很想获得反馈,了解哪些资源对我熟悉不同的框架很有用。谢谢! 最佳答案 世界变了!检查并赞成@prusswan我认为Test::Unit仍然具有相关性,尽管围绕BDD和其他测试工具进

Ruby: bool 正则表达式方法的正确语法是什么?

检查字符串中的模式并在正则表达式匹配时返回true或false的方法的正确语法是什么?基本思路:defhas_regex?(string)pattern=/something/ireturnstring=~patternend用例:ifhas_regex?("something")#woohooelse#nothingfound:panic!end 最佳答案 在你说的问题中:...methodthatchecksastringforapattern,andreturnstrueorfalseiftheregexmatches作为jo

ruby - 导轨/RSpec : How to test #initialize method?

如何使用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方法的期望值。

ruby-on-rails - 如何在 ruby​​ Test::Unit 框架中运行单个 shoulda 上下文测试

我通常可以对方法“delete_user_test”使用以下命令行语法来测试常规Test::Unit方法:rubyfunctional/user_controller_test.rb-ndelete_user_test现在,当我将shoulda插件与Test::Unit一起使用时,我尝试使用如下相同的技术:...context"DeletingaUser"doshould"removeuserfromusertable"do...endend然后我尝试按如下方式运行单个测试:rubyfunctional/user_controller_test.rb-n"test:DeletingaU