我正在尝试编写这样的代码:
assert_throws(:ExtractionFailed) { unit.extract_from('5 x 2005')}
Run Code Online (Sandbox Code Playgroud)
ExtractionFailed是一个简单的子类Exception,并且在test/unit下,我试图断言当我调用unit.extract_from时抛出它(...坏数据......)
我已经ExtractionFailed进入了SemanticText模块,所以现在test/unit说:
<:ExtractionFailed> expected to be thrown but
<:"SemanticText::ExtractionFailed"> was thrown.
Run Code Online (Sandbox Code Playgroud)
我尝试编写assert_throws(:SemanticText :: ExtractionFailed){...},但我得到了相当混乱的消息: TypeError: SemanticText is not a class/module
我可以通过执行以下操作使其工作(虽然它看起来像一个黑客):
assert_throws(SemanticText::ExtractionFailed.to_s.to_sym) { unit.extract_from('5 x 2005')}
Run Code Online (Sandbox Code Playgroud)
那么在红宝石中说这个断言的正确方法是什么?
我试图让Capybara使用rails 3(和测试单元)但是当我尝试运行时rake test:integration出现错误:ArgumentError: @request must be an ActionDispatch::Request
测试:
require 'integration_test_helper'
class UserNotesTest < ActionDispatch::IntegrationTest
test "User should login" do
user = Factory.create(:user)
visit '/login'
assert_response :success
fill_in 'user_email', :with => user.email
fill_in 'user_password', :with => user.password
click_button 'Sign in'
assert_redirect_to notes_path
end
end
Run Code Online (Sandbox Code Playgroud)
integration_test_helper:
require 'test_helper'
require 'capybara/rails'
module ActionDispatch
class IntegrationTest
include Capybara
end
end
Run Code Online (Sandbox Code Playgroud)
我不确定哪里出错了......
Ruby测试单元gem不会显示通过测试的点.我在Ubuntu 11.04上运行.
它显示"E"和"F"表示失败,但没有通过.如果我评论gem 'test-unit' 行,这个问题就会消失,但在这种情况下,测试单元2.x功能(如省略,挂起)不可用.
我使用Ruby 1.9.2(ruby -v产量:ruby 1.9.2p290(2011-07-09修订版32553)[x86_64-linux]),我试图让它工作:
require 'test/unit'
class TestStartup < Test::Unit::TestCase
def self.startup
puts "startup"
end
def test1
puts "in test1"
end
end
Run Code Online (Sandbox Code Playgroud)
当我跑的时候,我明白了
Loaded suite test_startup
Started
in test1
.
Finished in 0.000395 seconds.
1 tests, 0 assertions, 0 failures, 0 errors, 0 skips
Run Code Online (Sandbox Code Playgroud)
我很难找到关于这个功能的文档,除了SO上的零散帖子等.
是的,我想使用此功能而不是设置.
TIA
我现在将第三方Web服务称为我的应用程序的一部分.我正在使用RestClient gem来执行此操作.有很多工具可以做同样的事情,所以这无关紧要.
我很好奇的是有足够好的测试,没什么太花哨的,我可以模拟我的应用程序在第三方Web服务因任何原因不可用时的响应方式.无论是由于网络延迟/复杂性,我都超过了速率限制或超时,我只是希望能够采取类似HTTP状态代码的内容并测试我的应用程序在该事件中执行的操作.
使用Test :: Unit的最佳方法是什么?现在,对第三方服务的调用封装在我的一个控制器内.我有一个简单的模块,其中包含一些用于远程服务的不同端点的包装器方法.我只想确保我的应用程序在服务可用或不可用时做正确的事情.
在Test :: Unit旁边使用一个额外的框架,它可以"存根"正确的方式去做这个吗?显然我不能强制网络超时并开始破解像IPtables这样的东西,因为测试不值得花时间.我确信这个问题已经解决了一百万次,因为将Facebook和Twitter等内容集成到Web应用程序中如今非常受欢迎.当以强大/受控格式访问这些API时,如何测试失败?
Rails 3.2.1应用程序,使用minitest和autotest-rails宝石.
如果我运行"rake test",则输出为彩色.但是,如果我运行自动测试,输出不是彩色的.
使用自动测试时如何获得颜色输出?
这是我的test_helper.rb:
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'turn/autorun'
Turn.config do |c|
# use one of output formats:
# :outline - turn's original case/test outline mode [default]
# :progress - indicates progress with progress bar
# :dotted - test/unit's traditional dot-progress mode
# :pretty - new pretty reporter
# :marshal - dump output as YAML (normal run mode only)
# :cue - interactive testing
c.format = :pretty
# turn on invoke/execute tracing, enable …Run Code Online (Sandbox Code Playgroud) 我在一个ruby脚本中有4个测试,我使用命令运行
ruby test.rb
Run Code Online (Sandbox Code Playgroud)
外观看起来像
Loaded suite test
Started
....
Finished in 50.326546 seconds.
4 tests, 5 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
Run Code Online (Sandbox Code Playgroud)
我想要实现的是,并行运行所有4个测试而不是顺序测试.像4个线程一样运行一个测试,有效地将执行时间减少到4个测试中最慢的时间+并行执行的时间很少.
我遇到了这个,但这似乎并行运行多个ruby测试文件 - 比如说我有test1.rb,test2.rb test3.rb,然后所有这三个文件将并行运行.
任何帮助将不胜感激.
我们正在开发一个关于Ruby 1.9.3和Rails 3.2.1的应用程序.
最近,我们的单元测试在开始时变得迟钝.调用和执行需要大约15秒.一旦我看到"执行测试:单位",在看到任何输出之前还需要10秒钟.最后,任务完成,测试只需3秒即可自行执行.
可以接受3秒的单元测试.对于BDD/TDD,25秒加载时间是不现实的.
这是我跑步时会发生的事情rake test:units --trace:
** Invoke test:units (first_time)
** Invoke test:prepare (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:load
** Invoke db:test:load_schema (first_time)
** Invoke db:test:purge
** Execute db:test:load_schema
** Invoke db:schema:load (first_time)
** Invoke environment
** Execute db:schema:load
** Execute test:prepare
** …Run Code Online (Sandbox Code Playgroud) 我最近创建了一个Rails 4应用程序,由于某种原因,我的rake任务不包括在内test.这是一些用于演示问题的控制台操作:
> rake test:units
rake aborted!
Don't know how to build task 'test:units'
/Users/clozach/.rvm/gems/ruby-2.1.3@hoverfly/bin/ruby_executable_hooks:15:in `eval'
/Users/clozach/.rvm/gems/ruby-2.1.3@hoverfly/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)
Run Code Online (Sandbox Code Playgroud)
失败.:(
> rake test
>
Run Code Online (Sandbox Code Playgroud)
没有输出.:(
> rake -T --all | grep test
rake db:test:clone #
rake db:test:clone_schema #
rake db:test:clone_structure #
rake db:test:deprecated #
rake db:test:load #
rake db:test:load_schema #
rake db:test:load_structure #
rake db:test:prepare #
rake db:test:purge #
rake log:clear # Truncates all *.log files in log/ to zero bytes …Run Code Online (Sandbox Code Playgroud) 在我的 ContactForm 组件中,我有 2 个计算的 mapGetter
computed: {
...mapGetters(["language"]),
...mapGetters("authentication", ["loading"]),
Run Code Online (Sandbox Code Playgroud)
第一个在我的 stoe/getters.js 中定义
export const language = state => {
return state.language;
};
Run Code Online (Sandbox Code Playgroud)
第二个是在我的 store/modules/authentication.js 中定义的
const authentication = {
namespaced: true,
getters: {
user: state => {
return state.user
},
loading: state => {
return state.loading
}
Run Code Online (Sandbox Code Playgroud)
},
我正在尝试模拟我的 Vuex 商店,这对于第一个“语言”来说很容易,
export const storeMock = Object.freeze({
state: {},
actions: {},
getters: {
language: () => { . // <= FINE
return "en";
},
authentication: { . // <= …Run Code Online (Sandbox Code Playgroud)