问题标签 [minitest]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
180 浏览

ruby - "No tests." error in ruby unit tests

My original test for user.rb looks like this:

The test ran and obviously failed as there was no User class. When I added the User class like below:

it throws a "No tests." error. Actually, not only this one but all tests throw the same error now. I suspected that this has sth to do with ruby in general, because it happened after I gem installed dm-core and at the beginning it threw an error:

"Error loading RubyGems plugin "/home/barerd/.rvm/gems/ruby-1.9.3-p125/gems/rubygems-bundler-0.2.8/lib/rubygems_plugin.rb": cannot load such file -- rubygems_bundler/rubygems_bundler_installer (LoadError)"

But when I try to run tests of other apps, they all work fine. I use rvm 1.11.6 (stable) and ruby 1.9.3p125 (2012-02-16 revision 34643) [i386-cygwin] on a windows 7 by the way. Any clue to the error?

To note, the core module file kimsin.rb is as follows:

0 投票
1 回答
1314 浏览

ruby - 如何在 minitest 输出中显示 sinatra 错误和其他变量

我正在使用 minitest 测试和编码一个 sinatra 应用程序。目前,我使用 last_response.status 通过以下方式查看请求发生了什么:

显示错误,如“预期状态 200 但为 500”。但我想在 Rack ENV 中显示 sinatra.error,例如:

这样我就不必启动应用程序并在浏览器上检查它。我试过这段代码:

但它抛出了一个“要求#的私有方法'错误'”错误。

如何在 sinatra 错误输出中显示变量的值?

0 投票
1 回答
165 浏览

ruby - Ruby instance_eval confusion with load`

I am trying to test a single method in ruby. It is in a separate file so basically:

a.rb:

in my a_spec.rb

When I try to run my test, it says that my_method is a private method while I can actually call Object.hello_world outright. What gives?

Also, is there an easier way to test plain ruby methods(no classes or modules) with minitest?

0 投票
1 回答
948 浏览

ruby-on-rails - Rails 2.3 和 minitest

我想用现有的 Rails 2.3.14 应用程序尝试 minitest。我已经尝试了几种方法,但它们似乎都不起作用。

它基本上归结为这一点。当我将 minitest 添加到 Gemfile 时,我运行的所有测试bundle exec rake test都不会使用 minitest 执行。

问题是大多数测试用例扩展了 ActiveSupport::Testcase 或 ActionController::Testcase(扩展了 ActiveSupport::TestCase)。

通过查看此类的代码,我发现它已经(不知何故)支持 MiniTest:

(完整代码见https://github.com/rails/rails/blob/2-3-stable/activesupport/lib/active_support/test_case.rb )

我的问题是:

是否可以在 Rails 2.3 中使用 minitest 而不是 test::unit 而无需扩展 (MiniTest::Unit::TestCase)

0 投票
2 回答
426 浏览

ruby-on-rails - Minitest 在两次连续运行中给出不同的结果

我一直在玩 Minitest,并发现了我似乎无法找到解释的行为

我有一个非常简单的模型测试文件如下:

当我在“rake db:test:prepare”之后第一次运行此代码时,测试通过

当我连续第二次运行它时,它给了我一个错误:

test_0001_anonymous 0:00:00.132
错误 SQLite3::ConstraintException:列电子邮件不是唯一的:插入“用户”(“管理员”、“创建的_at”、“电子邮件”、“名称”、“密码摘要”、“更新的_at”)值( ?, ?, ?, ?, ?, ?)

然而,如果我取出这个错误似乎不会发生

我的 minitest_helper.rb 如下:

我似乎无法理解这是一个错误还是(更有可能)我遗漏了一些东西。比我更懂的人能解释一下吗?

0 投票
4 回答
25454 浏览

ruby - 如何断言某些方法被 Ruby minitest 框架调用?

我想测试一个函数是否使用 minitest Ruby 正确调用其他函数,但我无法从docassert中找到合适的测试对象。

源代码 测试代码:
0 投票
1 回答
841 浏览

ruby-on-rails - 如何在带有 MiniTest 的 Rails 3.2 中模拟“编辑”或“销毁”按钮?

如何编写用于编辑项目的集成测试?我的“创建”测试如下所示:

这很好用。我感到困惑的是如何进行编辑和销毁测试。我的索引页面提供了所有产品的列表。所以首先我使用工厂来创建几​​个产品。现在我处于有多个“编辑”和“销毁”按钮的情况。我不能只说:

因为有两个。我如何告诉它点击哪一个?

如果我确实点击了正确的“销毁”按钮,如何在弹出的 Javascript 窗口中点击“确定”按钮?

0 投票
0 回答
591 浏览

ruby-on-rails - RubyMine - 使用 Rails 运行单个测试使用了不正确的参数

我爱上了 Rubymine,但出于某种原因,运行单个测试将始终运行该类的整个测试套件。当我看到控制台输出时,我是这样的:

我正在使用 Rails 3.1.0,我的所有测试都是 ActiveSupport::TestCase 或 Rails 默认支持的其他测试类之一,我的 Gemfile 中没有额外的 gem。据我所知,Rails 默认使用 MiniTest。这是我看到的问题:

当我遵循 Rails 测试指南时,它说调用单个测试的语法应该是这样的:

所以使用-n method_name而不是--name=method_name

在常规控制台中运行后一个命令可以按预期工作。这似乎是 RubyMine 内部的东西,有没有办法改变这个设置,或者 Rails 默认测试框架目前不完全支持?

0 投票
1 回答
1361 浏览

ruby-on-rails - 用 minitest 测试 Rails 控制器方法

使用 minitest,测试这个 build_plan 方法的最佳方法是什么?

我目前的尝试是尝试验证 @account.plan 是否已设置,但我不太清楚如何做到这一点。这是我应该尝试做的,还是别的什么?

account_controller.rb

account_integration_test.rb

0 投票
1 回答
1120 浏览

ruby-on-rails - 在 minitest 中首次调用 skip() 会引发错误(nil:NilClass 的未定义方法“split”)

在 rails 3.2/minitest 项目中第一次调用“skip”时出现未定义的错误。

这很好用,但是如果我修改为跳过 Y ...

...它错误:

如果我添加第三个测试,也跳过,它只会在第一个跳过时报告错误:

任何人都可以就第一次遇到的跳过错误的原因提出建议吗?或者,也许,我应该在哪个问题跟踪器中提交这个问题?