Tag: minitest

我如何有效地强制Minitest按顺序运行我的测试?

我知道。 这是不鼓励的。 由于我不会进入的原因,我需要按照它们编写的顺序运行我的测试。 根据文档,如果我的测试类(我们称之为TestClass)扩展Minitest :: Unit :: TestCase,那么我应该能够调用公共方法i_suck_and_my_tests_are_order_dependent! (哎呀 – 你觉得创造Minitest的那个人对那个人有意见吗?)。 此外,还可以选择调用名为test_order的方法并指定:alpha来覆盖默认行为:random 。 这些都不适合我。 这是一个例子: class TestClass < Minitest::Unit::TestCase #override random test run ordering i_suck_and_my_tests_are_order_dependent! def setup …setup code end def teardown …teardown code end def test_1 test_1 code…. assert(stuff to assert here, etc…) puts 'test_1' end def test_2 test_2_code assert(stuff to assert here, etc…) […]

如何使用Minitest为Devise测试控制器sign_in

我是Rails测试的新手。 在线学习了一些教程后,我可以设置并运行Model的测试。 但是在尝试测试Controller时,测试失败了,因为它被重定向到登录页面。 我已经尝试过我可以在网上找到的所有指令来登录设计,但仍然无法登录并继续前进。 感谢是否有人可以提供帮助,并指导我前进的方向。 AwardedBidsControllerTest test_should_get_index FAIL (0.45s) MiniTest::Assertion: Expected response to be a , but was 以下是我的设置 测试/ test_helper.rb中 ENV[“RAILS_ENV”] = “test” require File.expand_path(“../../config/environment”, __FILE__) require “rails/test_help” require “minitest/rails” require “minitest/reporters” Minitest::Reporters.use!( Minitest::Reporters::SpecReporter.new, ENV, Minitest.backtrace_filter ) class ActiveSupport::TestCase fixtures :all include FactoryGirl::Syntax::Methods end class ActionController::TestCase include Devise::TestHelpers end 测试/控制器/ awarded_bids_controller_test.rb require “test_helper” class […]

Ruby minitest assert_output语法

我是minitest的新手,对ruby来说仍然是新人,并且真的厌倦了尝试google这个问题而没有结果。 我真的很感激你的帮助: ruby minitest中assert_output的确切语法是什么? 我在github或其他地方找到的所有内容似乎都使用括号。 然而,当我不使用带有assert_output的块时,我收到一条错误消息,这是有意义的,因为此方法的定义包含yield语句。 但无论我尝试什么,我都无法使它发挥作用。 testclass.rb class TestClass def output puts ‘hey’ end end test_test.rb require ‘minitest/spec’ require ‘minitest/autorun’ require_relative ‘testclass’ class TestTestClass < MiniTest::Unit::TestCase def setup @test = TestClass.new end def output_produces_output assert_output( stdout = 'hey' ) { @test.output} end end 我得到的是: 完成0.000000s的测试,NaN测试/ s,NaN断言 0次测试,0次断言,0次失败,0次错误,0次跳过 我究竟做错了什么? 它必须是非常明显的东西,但我无法弄清楚。 谢谢你的帮助。

minitest,test :: unit和rails

我读到某个地方’minitest’是“ruby 1.9.2+的新测试::单位”。 但ruby 1.9.3似乎包括test :: unit 和 minitest ,这是真的吗? 在默认的rails测试中,如Rails测试指南中所述 ……像ActiveSupport::TestCase , ActionController::TestCase这样的东西是使用Test::Unit还是Minitest ? 在rails指南中,它显示了如下定义的测试示例: test “should show post” do get :show, :id => @post.id assert_response :success end 在定义Test::Unit或Minitest的文档中没有提到该语法, test string ,而不是定义名称类似test_something方法。 来自哪里? Rails是否添加它,或者它实际上是…的一部分……无论是测试lib rails使用的是什么? PS:请不要告诉我“只使用rspec”。 我知道rspec。 我试图在rails的上下文中探索stdlib替代方案。

使用Ruby minitest创建测试套件

我正在将我的测试移动到新的ruby minitest库,我正在寻找与旧的Test :: Unit :: TestSuite类相对应的类。 我在网上找到的所有例子都显示了单个测试用例,但我得到了: require ‘minitest/unit/testsuite’ require ‘minitest/unit/ui/console/testrunner’ require ‘tests/fs_session_test’ require ‘tests/resource_test’ require ‘tests/rest_session_test’ require ‘tests/server_test’ class AllTests def self.suite suite = Test::Unit::TestSuite.new suite << FSSessionTest.suite suite << ResourceTest.suite suite << RESTSessionTest.suite suite << ServerTest.suite end end Test::Unit::UI::Console::TestRunner.run(AllTests) 我一直在testsuite require上得到一个LoadError。

如何使用Ruby minitest框架调用某些方法?

我想测试一个函数是否使用minitest Ruby正确调用其他函数,但我找不到一个适当的assert来测试doc 。 源代码 class SomeClass def invoke_function(name) name == “right” ? right () : wrong () end def right #… end def wrong #… end end 测试代码: describe SomeClass do it “should invoke right function” do # assert right() is called end it “should invoke other function” do # assert wrong() is called end […]

测试使用ActiveRecord的问题/模块

场景我提取了一个名为Taggable 。 它是一个允许任何模型支持标记的模块。 我已将此问题/模块包含在User , Location , Location , Projects 。 我想为这个模块编写测试,但不知道从哪里开始。 题 1.我可以对Taggable问题进行隔离测试吗? 在下面的示例中,测试失败,因为测试正在查找dummy_class table 。 我假设它正在这样做是因为Taggable中的has_many代码,因此它希望’DummyClass’成为ActiveRecord对象。 # /app/models/concerns/taggable.rb module Taggable extend ActiveSupport::Concern included do has_many :taggings, :as => :taggable, :dependent=> :destroy has_many :tags, :through => :taggings end def tag(name) name.strip! tag = Tag.find_or_create_by_name(name) self.taggings.find_or_create_by_tag_id(tag.id) end end # /test/models/concerns/taggable_test.rb require ‘test_helpers’ class DummyClass end […]

使用MiniTest检查模型上的方法调用

如果我使用RSpec,我可以测试是否正在调用方法: expect(obj).to receive(:method) MiniTest中的等价物是什么? 我有一个模型Post ,它有一个before_validation回调,它运行一个方法create_slug 。 在我的测试test/models/post_test.rb我想确保在调用post.save时调用create_slug方法。 Minitest :: Spec文档说我可以使用方法must_send来检查方法是否被调用。 但是,当我尝试@post.must_send :create_slug我收到以下错误: NoMethodError: undefined method `must_send’ for # 我在test_helper.rb文件中包含Minitest :: Spec: ENV[‘RAILS_ENV’] ||= ‘test’ require File.expand_path(‘../../config/environment’, __FILE__) require ‘rails/test_help’ require ‘minitest/spec’ class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. # # Note: You’ll currently still have to declare […]

Ruby Minitest:套件级或类级设置?

使用内置的Ruby Minitest框架,有没有办法在整个套件运行之前运行一些代码,甚至在整个TestClass运行之前运行一次? 我在这个问题的答案中看到Test :: Unit :: after_tests可用于在所有测试运行后运行代码; 是否有类似的方法在所有测试运行之前运行代码? 我希望在测试运行之前使用此function初始化测试数据库,并在它们全部运行后将其拆除。 谢谢!