Passing a parameter / object to a ruby ​​block / test before running it with TestRunner

I create a tool that automates the process, then runs some tests on its own results, then performs some other actions.

While trying to clear my code, I created a separate file that just has a class of test cases. Now, before I can run these tests, I must pass a couple of parameters / objects to the class before they can be run. Now the problem is that I cannot find a way to pass the parameter / object to the test class.

At the moment, I'm going to create a Yaml file and read it in a test class, but it considers it "wrong" to use a temporary file for this. If someone has a more pleasant solution, it will be great!

************** Edit ************

Sample code for what I'm doing right now:

#!/usr/bin/ruby
require 'test/unit/ui/console/testrunner'
require 'yaml'
require 'TS_SampleTestSuite'

automatingSomething()
importantInfo = getImportantInfo()

File.open('filename.yml', 'w') do |f|
    f.puts importantInfo.to_yaml
end

Test::Unit::UI::Console::TestRunner.run(TS_SampleTestSuite)

Now, in the example above, TS_SampleTestSuite needs importantInfo, so the first “test case” is a method that simply reads in the information from the Yaml filname.yml file.

I hope this confuses some confusion.

+3
source share
2 answers

All in all, it looks like you are not really using unit tests very ruby, but I will leave this aside for a moment.

Your main problem is that you have some kind of setup that must happen before running the tests. The usual way to do this is by using the installation method in the test block body itself.

class UserTest < TestUnit::TestCase

  def setup
    # do your important calculation
  end

  def test_success
    #.. assert some things
  end
end

, , , , .

0

-, Cameron, , .

, (.. ), . , importantInfo, IMPORTANT_INFO. . , , , , .

, importantInfo, , , .

0

Source: https://habr.com/ru/post/1699485/


All Articles