Skip to content

Instantly share code, notes, and snippets.

@y-yagi
Created January 3, 2017 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y-yagi/f7289d8211d8c1593192314475b3c86a to your computer and use it in GitHub Desktop.
Save y-yagi/f7289d8211d8c1593192314475b3c86a to your computer and use it in GitHub Desktop.
stub_any_instance sample
require "abstract_unit"
require "active_support/testing/method_call_assertions"
require "rails/command"
require "rails/commands/server/server_command"
class Rails::Engine::CommandsTasksTest < ActiveSupport::TestCase
include ActiveSupport::Testing::MethodCallAssertions
def setup
@destination_root = Dir.mktmpdir("bukkits")
Dir.chdir(@destination_root) { `bundle exec rails plugin new bukkits --mountable` }
self.class.const_set("ENGINE_PATH", "rails/all")
end
def teardown
FileUtils.rm_rf(@destination_root)
end
def test_help_command_work_inside_engine
output = capture(:stderr) do
Dir.chdir(plugin_path) { `bin/rails --help` }
end
assert_no_match "NameError", output
end
def test_server_command_work_inside_engine
stub_any_instance(Rails::Server) do |instance|
assert_called_with(instance, :start) do
Rails::Command.invoke(:server)
end
end
ensure
end
private
def plugin_path
"#{@destination_root}/bukkits"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment