Skip to content

Commit

Permalink
Merge pull request #41203 from jonathanhefner/generator-test-stub-tho…
Browse files Browse the repository at this point in the history
…r-apply

Avoid testing Thor internals
  • Loading branch information
rafaelfranca committed Jan 22, 2021
1 parent 0a1e4c2 commit bcb5737
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions railties/test/generators/shared_generator_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,17 @@ def test_template_raises_an_error_with_invalid_path
end

def test_template_is_executed_when_supplied_an_https_path
path = "https://gist.github.com/josevalim/103208/raw/"
template = +%{ say "It works!" }
template.instance_eval "def read; self; end" # Make the string respond to read
url = "https://gist.github.com/josevalim/103208/raw/"
generator([destination_root], template: url, skip_webpack_install: true)

check_open = -> *args do
assert_equal [ path, "Accept" => "application/x-thor-template" ], args
template
end
applied = nil
apply_stub = -> (path, *) { applied = path }

generator([destination_root], template: path, skip_webpack_install: true).stub(:open, check_open, template) do
generator.stub :bundle_command, nil do
quietly { assert_match(/It works!/, capture(:stdout) { generator.invoke_all }) }
end
generator.stub(:apply, apply_stub) do
quietly { generator.invoke_all }
end

assert_equal url, applied
end

def test_skip_gemfile
Expand Down

0 comments on commit bcb5737

Please sign in to comment.