草庐IT

setup_test_data

全部标签

ruby - 在 Rack::Test 中使用 Cookie

我正在尝试使用Rack::Test为我的Sinatra应用程序编写RSpec测试。我不明白如何使用cookie。例如,如果我的应用程序设置了cookie(不是通过:session),我如何检查该cookie是否设置正确?另外,我如何使用该cookie发送请求? 最佳答案 Rack::Test保留一个cookiejar,该cookiejar在请求期间持续存在。您可以使用rack_mock_session.cookies访问它。假设您有这样的处理程序:get'/cookie/set'doresponse.set_cookie"foo",

ruby 公案 : test_nil_is_an_object

我最近尝试使用这个工具来提高我的Rails技能:http://github.com/edgecase/ruby_koans但我无法通过一些测试。此外,我不确定我是否正确地做了一些事情,因为目标只是通过测试,有很多方法可以通过它,我可能正在做一些不符合标准的事情。有没有办法确认我做的事情是否正确?具体例子:在about_nil中,deftest_nil_is_an_objectassert_equal__,nil.is_a?(Object),"UnlikeNULLinotherlanguages"end它是告诉我检查第二个子句是否等于一个对象(所以我可以说nil是一个对象)或者只是把as

ruby - Pod setup 找不到 cocoapods

使用sudogeminstallcocoapods安装cocoapods后,尝试运行“podsetup”会返回此错误:Couldnotfind'cocoapods'(>=0)among22totalgem(s)(Gem::LoadError)“pod设置”的输出:/Users/Kevin/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:313:in`to_specs':Couldnotfind'cocoapods'(>=0)among22totalgem(s)(Gem::LoadEr

ruby-on-rails - 如何呈现 XML 模板,然后在 Ruby on Rails 3.2.8 中使用 SEND_DATA?

谁能帮我处理XML模板渲染和发送数据?我有一个Controller:defshow@calculation=Calculation.find(params[:id])respond_todo|format|format.html#show.html.erbformat.json{renderjson:@calculation}format.xml{send_data(:partial=>show.xml.erb,:filename=>"my_file.xml")}format.pdf{render:format=>false}endend但是我有很多关于“堆栈级别太深”的错误如果我用{

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-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-on-rails - rails : creating a custom data type/creating a shorthand

我想知道如何创建自定义数据类型以在rake迁移文件中使用。示例:如果您要创建模型,则可以在迁移文件中添加列。它可能看起来像这样:defself.upcreate_table:productsdo|t|t.column:name,:stringt.timestampsendend我想知道如何创建这样的东西:t.column:name,:my_custom_data_type之所以这样创建,例如一个“货币”类型,无非是一个精度为8,小数位数为2的小数。由于我只使用MySQL,所以这个数据库的解决方案已经足够了。感谢您的反馈和意见! 最佳答案

ruby - bundle exec 和 require 'bundler/setup' 是否等效?

这些事情完成的是否完全相同?使用bundleexecruby​​foo.rb启动ruby​​进程将require"bundler/setup"作为foo.rb的第一行 最佳答案 在您的特定示例中,它们可以被认为是相同的,但实际上它们并不相同。bundleexec对bundler/setup没有进行的环境进行了一些更改。如果您的foo.rb从不运行子shell,或者从不尝试在子shell中运行其他ruby​​可执行文件,那么这两个版本是等效的(它们都将正确加载bundle的gem并且工作完全相同)。bundleexec的整个想法是让您

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