Created
January 3, 2017 01:27
-
-
Save y-yagi/f7289d8211d8c1593192314475b3c86a to your computer and use it in GitHub Desktop.
stub_any_instance sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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