小编SoS*_*ple的帖子

Minitest - 测试不运行 - 没有Rails

我刚刚开始一个小型项目来模仿嘉年华的售票亭,其中一个指导方针是测试用户是否可以输入门票数量.该程序在控制台中运行,我最终(希望)想出了如何实现这个测试,感谢@ Stefan对这个问题的回答.

问题是,现在,当我运行测试文件时,minitest说:

0次运行,0次断言,0次失败,0次错误,0次跳过

当我尝试使用名称运行测试时,我得到相同的结果ruby path/to/test/file.rb --name method-name.我不确定这是不是因为我的代码仍然有问题,因为我是因为我错误地设置了minitest.我试图在SO上查找类似的问题,但大多数问题似乎涉及使用minitest和rails,我只是有一个普通的ruby项目.

这是我的测试文件:

gem 'minitest', '>= 5.0.0'
require 'minitest/spec'
require 'minitest/autorun'
require_relative 'carnival'

class CarnivalTest < MiniTest::Test
  def sample
    assert_equal(1, 1)
  end

  def user_can_enter_number_of_tickets
    with_stdin do |user|
      user.puts "2"
      assert_equal(Carnival.new.get_value, "2")
    end
  end

  def with_stdin
    stdin = $stdin                 # global var to remember $stdin
    $stdin, write = IO.pipe        # assign 'read end' of pipe to $stdin
    yield write                    # pass 'write end' to block
  ensure
    write.close                    # close pipe
    $stdin …
Run Code Online (Sandbox Code Playgroud)

ruby minitest

3
推荐指数
1
解决办法
1388
查看次数

标签 统计

minitest ×1

ruby ×1