Skip to content

Commit

Permalink
Refactor test setup and generate_todo_existing in StandardrbTest
Browse files Browse the repository at this point in the history
- Refactored the before_setup method to include additional setup steps.
- Updated the generate_todo_existing test to use a separate test folder and fixture folder for better organization.
- Modified file paths in the generate_todo_existing test to reflect the new folder structure.
  • Loading branch information
mrbiggred committed Aug 21, 2023
1 parent 45ebde6 commit cd1d59f
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions test/standardrb_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
require "open3"

class StandardrbTest < UnitTest
TEST_ROOT_FOLDER = "tmp/tests/standardrb"

def before_setup
super

FileUtils.rm_rf(TEST_ROOT_FOLDER)
FileUtils.mkdir_p(TEST_ROOT_FOLDER)
end

def test_project_a_failure_output
stdout, status = run_standardrb("test/fixture/project/a")

Expand Down Expand Up @@ -33,21 +42,20 @@ def test_generate_todo

def test_generate_todo_existing
config_file = "./.standard.yml"
test_folder = File.join(TEST_ROOT_FOLDER, "generate_todo_existing")
fixture_folder = "test/fixture/standardrb/generate_todo_existing"

FileUtils.rm_rf("tmp/tests/standardrb/generate_todo_existing")
FileUtils.mkdir_p("tmp/tests/standardrb")

FileUtils.cp_r(File.join("test/fixture/standardrb/generate_todo_existing", "."), "tmp/tests/standardrb/generate_todo_existing")
FileUtils.cp_r(File.join(fixture_folder, "."), test_folder)

stdout, status = run_standardrb("tmp/tests/standardrb/generate_todo_existing", ["--generate-todo", "--config", config_file])
stdout, status = run_standardrb(test_folder, ["--generate-todo", "--config", config_file])

# The generate todo returns the Rubocop result which is non-zero
# if any linting errors where found.
refute status.success?
assert_equal "", stdout

assert File.exist?(File.join("tmp/tests/standardrb/generate_todo_existing", ".standard_todo.yml"))
assert_equal File.read(File.join("tmp/tests/standardrb/generate_todo_existing", ".standard_todo_expected.yml")), File.read(File.join("tmp/tests/standardrb/generate_todo_existing", ".standard_todo.yml"))
assert File.exist?(File.join(test_folder, ".standard_todo.yml"))
assert_equal File.read(File.join(test_folder, ".standard_todo_expected.yml")), File.read(File.join(test_folder, ".standard_todo.yml"))
end

def test_project_a_forwards_rubocop_options
Expand Down

0 comments on commit cd1d59f

Please sign in to comment.