proxy_tester 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. data/.gitignore +22 -0
  2. data/.rdebugrc +7 -0
  3. data/.rspec +3 -0
  4. data/.simplecov +8 -0
  5. data/Gemfile +37 -0
  6. data/Gemfile.lock +199 -0
  7. data/LICENSE.txt +22 -0
  8. data/Procfile +1 -0
  9. data/README.md +582 -0
  10. data/Rakefile +64 -0
  11. data/bin/proxy_tester +11 -0
  12. data/db/migrate/20140314_create_environment.rb +8 -0
  13. data/files/config.yaml +1 -0
  14. data/files/example-config.erb +12 -0
  15. data/files/example-spec_helper.rb.erb +23 -0
  16. data/files/example-test_case.rb.erb +27 -0
  17. data/files/example-test_cases-gemfile.rb.erb +9 -0
  18. data/files/example-user_file.erb +4 -0
  19. data/lib/proxy_tester/actions/add_examples_to_test_cases_directory.rb +125 -0
  20. data/lib/proxy_tester/actions/clone_repository.rb +39 -0
  21. data/lib/proxy_tester/actions/create_directory.rb +33 -0
  22. data/lib/proxy_tester/actions/create_file.rb +55 -0
  23. data/lib/proxy_tester/actions/create_output.rb +36 -0
  24. data/lib/proxy_tester/actions/handle_error.rb +37 -0
  25. data/lib/proxy_tester/actions/initialize_application.rb +70 -0
  26. data/lib/proxy_tester/actions/show_config.rb +10 -0
  27. data/lib/proxy_tester/capybara_proxy.rb +54 -0
  28. data/lib/proxy_tester/capybara_proxy_pac.rb +62 -0
  29. data/lib/proxy_tester/cli/main.rb +59 -0
  30. data/lib/proxy_tester/config.rb +100 -0
  31. data/lib/proxy_tester/data.rb +23 -0
  32. data/lib/proxy_tester/database_session.rb +15 -0
  33. data/lib/proxy_tester/environment.rb +21 -0
  34. data/lib/proxy_tester/erb_generator.rb +34 -0
  35. data/lib/proxy_tester/error_handler.rb +107 -0
  36. data/lib/proxy_tester/error_messages.rb +82 -0
  37. data/lib/proxy_tester/exceptions.rb +53 -0
  38. data/lib/proxy_tester/git_file.rb +31 -0
  39. data/lib/proxy_tester/git_null_file.rb +32 -0
  40. data/lib/proxy_tester/git_repository.rb +120 -0
  41. data/lib/proxy_tester/handle_error.rb +37 -0
  42. data/lib/proxy_tester/locales/en-rails.yml +205 -0
  43. data/lib/proxy_tester/locales/en.yml +42 -0
  44. data/lib/proxy_tester/main.rb +46 -0
  45. data/lib/proxy_tester/models/user.rb +17 -0
  46. data/lib/proxy_tester/pac_result.rb +50 -0
  47. data/lib/proxy_tester/rspec/helper.rb +211 -0
  48. data/lib/proxy_tester/rspec_runner.rb +43 -0
  49. data/lib/proxy_tester/template_file.rb +19 -0
  50. data/lib/proxy_tester/template_repository.rb +22 -0
  51. data/lib/proxy_tester/ui_logger.rb +30 -0
  52. data/lib/proxy_tester/user_database.rb +24 -0
  53. data/lib/proxy_tester/version.rb +3 -0
  54. data/lib/proxy_tester.rb +54 -0
  55. data/proxy_tester.gemspec +34 -0
  56. data/script/acceptance_test +4 -0
  57. data/script/bootstrap +56 -0
  58. data/script/ci +3 -0
  59. data/script/console +14 -0
  60. data/script/release +3 -0
  61. data/script/test_web +22 -0
  62. data/script/unit_test +3 -0
  63. data/spec/actions/add_examples_to_test_cases_directory_spec.rb +52 -0
  64. data/spec/actions/clone_repository_spec.rb +83 -0
  65. data/spec/actions/create_directory_spec.rb +59 -0
  66. data/spec/actions/create_file_spec.rb +139 -0
  67. data/spec/actions/create_output_spec.rb +46 -0
  68. data/spec/actions/handle_error_spec.rb +74 -0
  69. data/spec/actions/initialize_application_spec.rb +40 -0
  70. data/spec/actions/show_config_spec.rb +22 -0
  71. data/spec/capybara_proxy_pac_spec.rb +42 -0
  72. data/spec/capybara_proxy_spec.rb +76 -0
  73. data/spec/config_spec.rb +86 -0
  74. data/spec/data_spec.rb +34 -0
  75. data/spec/environment_spec.rb +25 -0
  76. data/spec/erb_generator_spec.rb +31 -0
  77. data/spec/examples/proxy.pac +7 -0
  78. data/spec/factories.rb +8 -0
  79. data/spec/features/check_ssl_sites_spec.rb +8 -0
  80. data/spec/git_file_spec.rb +46 -0
  81. data/spec/git_repository_spec.rb +111 -0
  82. data/spec/main_spec.rb +25 -0
  83. data/spec/pac_result_spec.rb +20 -0
  84. data/spec/proxy_tester_spec_helper_spec.rb +137 -0
  85. data/spec/rspec_runner_spec.rb +29 -0
  86. data/spec/spec_helper.rb +15 -0
  87. data/spec/support/capybara.rb +11 -0
  88. data/spec/support/database_cleaner.rb +14 -0
  89. data/spec/support/debugging.rb +3 -0
  90. data/spec/support/environment.rb +33 -0
  91. data/spec/support/example.rb +16 -0
  92. data/spec/support/factory_girl.rb +15 -0
  93. data/spec/support/filesystem.rb +19 -0
  94. data/spec/support/helper_features.rb +31 -0
  95. data/spec/support/matcher.rb +17 -0
  96. data/spec/support/reporting.rb +1 -0
  97. data/spec/support/rspec.rb +5 -0
  98. data/spec/support/string.rb +2 -0
  99. data/spec/template_file_spec.rb +25 -0
  100. data/spec/template_repository_spec.rb +44 -0
  101. data/spec/user_database_spec.rb +63 -0
  102. data/spec/user_spec.rb +62 -0
  103. metadata +398 -0
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ module ProxyTester
3
+ class UserDatabase
4
+ private
5
+
6
+ attr_reader :file
7
+
8
+ public
9
+
10
+ def initialize(file = ProxyTester.config.user_file)
11
+ @file = file
12
+ end
13
+
14
+ def create_users(creator)
15
+ raise Exceptions::UserFileNotFound, file: file unless ::File.exist? file
16
+
17
+ CSV.foreach(file, headers: true) do |r|
18
+ creator.create! name: r['name'], password: r['password']
19
+ end
20
+ rescue ActiveRecord::RecordInvalid => err
21
+ raise Exceptions::UserRecordInvalid, message: err.message
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module ProxyTester
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+ require 'active_record'
3
+ require 'active_support/core_ext/kernel/reporting'
4
+ require 'active_support/core_ext/object/blank'
5
+ require 'active_support/core_ext/array/access'
6
+ require 'crypt_keeper'
7
+ require 'addressable/uri'
8
+ require 'io/console'
9
+ require 'json'
10
+ require 'fuubar'
11
+ require 'rspec'
12
+ require 'thor'
13
+ require 'logger'
14
+ require 'rugged'
15
+ require 'capybara/rspec'
16
+ require 'capybara/poltergeist'
17
+ require 'ostruct'
18
+ require 'csv'
19
+ require 'proxy_pac_rb'
20
+
21
+ require 'proxy_tester/models/user'
22
+
23
+ require 'proxy_tester/pac_result'
24
+ require 'proxy_tester/capybara_proxy_pac'
25
+ require 'proxy_tester/user_database'
26
+ require 'proxy_tester/ui_logger'
27
+ require 'proxy_tester/erb_generator'
28
+ require 'proxy_tester/config'
29
+ require 'proxy_tester/exceptions'
30
+ require 'proxy_tester/version'
31
+ require 'proxy_tester/database_session'
32
+ require 'proxy_tester/environment'
33
+ require 'proxy_tester/main'
34
+ require 'proxy_tester/data'
35
+ require 'proxy_tester/template_repository'
36
+ require 'proxy_tester/template_file'
37
+ require 'proxy_tester/git_null_file'
38
+ require 'proxy_tester/git_file'
39
+ require 'proxy_tester/git_repository'
40
+ require 'proxy_tester/error_handler'
41
+ require 'proxy_tester/rspec_runner'
42
+ require 'proxy_tester/cli/main'
43
+
44
+ require 'proxy_tester/actions/show_config'
45
+ require 'proxy_tester/actions/initialize_application'
46
+ require 'proxy_tester/actions/create_output'
47
+ require 'proxy_tester/actions/create_directory'
48
+ require 'proxy_tester/actions/create_file'
49
+ require 'proxy_tester/actions/handle_error'
50
+ require 'proxy_tester/actions/clone_repository'
51
+ require 'proxy_tester/actions/add_examples_to_test_cases_directory'
52
+
53
+ require 'proxy_tester/capybara_proxy'
54
+ require 'proxy_tester/rspec/helper'
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'proxy_tester/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'proxy_tester'
9
+ spec.version = ProxyTester::VERSION
10
+ spec.authors = ['Dennis Günnewig']
11
+ spec.email = ['dg1@vrnetze.de']
12
+ spec.summary = %q{Test proxies}
13
+ spec.description = %q{Test proxies to be sure it works}
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'activerecord', '~>4.0'
22
+ spec.add_runtime_dependency 'activesupport', '~>4.0'
23
+ spec.add_runtime_dependency 'sqlite3'
24
+ spec.add_runtime_dependency 'crypt_keeper'
25
+ spec.add_runtime_dependency 'rspec'
26
+ spec.add_runtime_dependency 'fuubar'
27
+ spec.add_runtime_dependency 'thor'
28
+ spec.add_runtime_dependency 'i18n'
29
+ spec.add_runtime_dependency 'rugged'
30
+ spec.add_runtime_dependency 'addressable'
31
+ spec.add_runtime_dependency 'poltergeist'
32
+ spec.add_runtime_dependency 'proxy_pac_rb', '~>0.2.5'
33
+ spec.add_runtime_dependency 'therubyracer'
34
+ end
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+
3
+ bundle exec cucumber
4
+ bundle exec rspec spec/features
data/script/bootstrap ADDED
@@ -0,0 +1,56 @@
1
+ #!/bin/sh
2
+
3
+ function puts() {
4
+ echo -e $1 >&2
5
+ }
6
+
7
+ function install_package() {
8
+ if which pacman > /dev/null; then
9
+ if [ -z "$(pacman -Ss "^$1\$" | grep installed)" ]; then
10
+ puts "Installing $1"
11
+ sudo pacman -S --noconfirm $1
12
+ fi
13
+ else
14
+ puts "Please install $1 from your operating system repository."
15
+ fi
16
+ }
17
+
18
+ function install_gem() {
19
+ if which gem > /dev/null; then
20
+ if [ -z "$(gem list -l "^$1\$")" ]; then
21
+ puts "Installing $1"
22
+ gem install --no-ri --no-rdoc $1
23
+ fi
24
+ else
25
+ puts "Please install $1 via rubygems."
26
+ fi
27
+ }
28
+
29
+ function install_node() {
30
+ if which npm > /dev/null; then
31
+ if [ -z "$(npm list -g $1 | grep bower)" ]; then
32
+ puts "Installing $1"
33
+ npm install -g $1
34
+ fi
35
+ else
36
+ puts "Please install $1 via npm"
37
+ fi
38
+ }
39
+
40
+ function file_exist() {
41
+ if [ -f $1 ]; then
42
+ puts "$2"
43
+ return 0
44
+ else
45
+ puts "Warning file \"$1\" does not exist. Maybe this can cause problems during bootstrapping"
46
+ return 1
47
+ fi
48
+ }
49
+
50
+ echo "Bootstrapping development environment for application.." >&2
51
+
52
+ install_package ruby
53
+ install_package phantomjs
54
+
55
+ install_gem bundler
56
+ bundle install
data/script/ci ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ bundle exec rake test:coveralls
data/script/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << ::File.expand_path('../../lib', __FILE__)
4
+
5
+ # Pull in all of the gems including those in the `test` group
6
+ require 'bundler'
7
+ Bundler.require :default, :test, :development
8
+
9
+ require 'irb'
10
+ require 'irb/completion'
11
+ require 'proxy_tester'
12
+
13
+ ARGV.clear
14
+ IRB.start
data/script/release ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ bundle exec rake gem:release
data/script/test_web ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sinatra'
4
+
5
+ class Webserver < Sinatra::Base
6
+ enable :protection
7
+
8
+ get '/:name' do
9
+ File.read(File.expand_path("../../files/test/#{params[:name]}", __FILE__))
10
+ end
11
+
12
+ post '/rspec/:test' do
13
+ case params[:test]
14
+ when 'send'
15
+ if params[:hello] == 'world'
16
+ 'hello rspec'
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ Webserver.start!
data/script/unit_test ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ bundle exec rspec
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Actions::AddExamplesToTestCasesDirectory do
5
+ let(:examples_directory) { File.join(working_directory, 'test_cases.d', 'examples') }
6
+
7
+ let(:repo) do
8
+ Rugged::Repository.init_at(git_repo)
9
+ end
10
+ context '#initialize' do
11
+ it 'requires a path' do
12
+ Actions::AddExamplesToTestCasesDirectory.new(examples_directory)
13
+ end
14
+ end
15
+
16
+ context '#run' do
17
+ it 'runs the action' do
18
+ action = Actions::AddExamplesToTestCasesDirectory.new(examples_directory)
19
+ silence(:stderr) do
20
+ action.run
21
+ end
22
+
23
+ expect(path_exists?('test_cases.d/examples')).to be_true
24
+ end
25
+
26
+ it 'respects existing path' do
27
+ create_directory('test_cases.d/examples')
28
+
29
+ action = Actions::AddExamplesToTestCasesDirectory.new(examples_directory)
30
+
31
+ result = capture(:stderr) do
32
+ ProxyTester.ui_logger.level = :info
33
+ action.run
34
+ end
35
+
36
+ expect(result).to include('already')
37
+ end
38
+
39
+ it 'does overwrite existing files if forced to' do
40
+ create_directory('test_cases.d/examples')
41
+
42
+ action = Actions::AddExamplesToTestCasesDirectory.new(examples_directory, force: true)
43
+
44
+ result = capture(:stderr) do
45
+ ProxyTester.ui_logger.level = :info
46
+ action.run
47
+ end
48
+
49
+ expect(result).to include('Creating')
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,83 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Actions::CloneRepository do
5
+ let(:source_git_repo) { File.join(working_directory, 'git_repo.git') }
6
+ let(:destination_git_repo) { File.join(working_directory, 'git_clone_repo') }
7
+
8
+ context '#initialize' do
9
+ it 'requires a source and a destination' do
10
+ repo = GitRepository.create(source_git_repo)
11
+ repo.add_content('file.txt', 'asdf1')
12
+
13
+ expect {
14
+ Actions::CloneRepository.new(source_git_repo, destination_git_repo)
15
+ }.not_to raise_error
16
+ end
17
+ end
18
+
19
+ context '#run' do
20
+ it 'runs the action' do
21
+ repo = GitRepository.create(source_git_repo)
22
+ repo.add_content('file.txt', 'asdf1')
23
+
24
+ action = Actions::CloneRepository.new(source_git_repo, destination_git_repo)
25
+ silence(:stderr) do
26
+ action.run
27
+ end
28
+
29
+ expect(path_exists?('git_clone_repo')).to be_true
30
+ end
31
+
32
+ it 'respects existing path' do
33
+ repo = GitRepository.create(source_git_repo)
34
+ repo.add_content('file.txt', 'asdf1')
35
+
36
+ create_directory('git_clone_repo')
37
+
38
+ action = Actions::CloneRepository.new(source_git_repo, destination_git_repo)
39
+
40
+ result = capture(:stderr) do
41
+ ProxyTester.ui_logger.level = :info
42
+ action.run
43
+ end
44
+
45
+ expect(result).to include('already')
46
+ end
47
+
48
+ it 'does !!!not!!! remove existing path if forced to' do
49
+ repo = GitRepository.create(source_git_repo)
50
+ repo.add_content('file.txt', 'asdf1')
51
+
52
+ create_directory('git_clone_repo')
53
+
54
+ action = Actions::CloneRepository.new(source_git_repo, destination_git_repo, force: true)
55
+
56
+ result = capture(:stderr) do
57
+ ProxyTester.ui_logger.level = :info
58
+ action.run
59
+ end
60
+
61
+ expect(result).to include('yourself')
62
+ end
63
+
64
+ it 'resolves ~' do
65
+ source_git_repo = '~/source_repo.git'
66
+ destination_git_repo = '~/destination_repo'
67
+
68
+
69
+ action = with_environment 'HOME' => working_directory do
70
+ repo = GitRepository.create(source_git_repo)
71
+ repo.add_content('file.txt', 'asdf1')
72
+
73
+ Actions::CloneRepository.new(source_git_repo, destination_git_repo)
74
+ end
75
+
76
+ silence(:stderr) do
77
+ action.run
78
+ end
79
+
80
+ expect(path_exists?('destination_repo/file.txt')).to be_true
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Actions::CreateDirectory do
5
+ context '#initialize' do
6
+ it 'requires a path' do
7
+ Actions::CreateDirectory.new(working_directory)
8
+ end
9
+ end
10
+
11
+ context '#run' do
12
+ it 'runs the action' do
13
+ action = Actions::CreateDirectory.new(::File.join(working_directory, 'repo'))
14
+ silence(:stderr) do
15
+ action.run
16
+ end
17
+
18
+ expect(path_exists?('repo')).to be_true
19
+ end
20
+
21
+ it 'respects existing path' do
22
+ create_directory('repo')
23
+
24
+ action = Actions::CreateDirectory.new(::File.join(working_directory, 'repo'))
25
+
26
+ result = capture(:stderr) do
27
+ ProxyTester.ui_logger.level = :info
28
+ action.run
29
+ end
30
+
31
+ expect(result).to include('already')
32
+ end
33
+
34
+ it 'does not respect existing path if forced to' do
35
+ create_directory('repo')
36
+
37
+ action = Actions::CreateDirectory.new(::File.join(working_directory, 'repo'), force: true)
38
+
39
+ result = capture(:stderr) do
40
+ ProxyTester.ui_logger.level = :info
41
+ action.run
42
+ end
43
+
44
+ expect(result).to include('Creating directory')
45
+ end
46
+
47
+ it 'resolves ~' do
48
+ action = with_environment 'HOME' => working_directory do
49
+ Actions::CreateDirectory.new('~/file')
50
+ end
51
+
52
+ silence(:stderr) do
53
+ action.run
54
+ end
55
+
56
+ expect(path_exists?('file')).to be_true
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,139 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Actions::CreateFile do
5
+ context '#initialize' do
6
+ it 'requires a path' do
7
+ repository = double('TemplateRepository')
8
+ data = double('Data')
9
+
10
+ engine_klass = Class.new do
11
+ def initialize(data)
12
+ end
13
+
14
+ def compile(template, destination)
15
+ end
16
+ end
17
+
18
+ Actions::CreateFile.new(:template, ::File.join(working_directory, 'file'), {}, data, engine_klass, repository)
19
+ end
20
+ end
21
+
22
+ context '#run' do
23
+ it 'runs the action' do
24
+ repository = double('TemplateRepository')
25
+ expect(repository).to receive(:find).with(:template)
26
+
27
+ data = double('Data')
28
+
29
+ engine_klass = Class.new do
30
+ def initialize(data)
31
+ end
32
+
33
+ def compile(template, destination)
34
+ end
35
+ end
36
+
37
+ action = Actions::CreateFile.new(:template, ::File.join(working_directory, 'file'), data, {}, engine_klass, repository)
38
+ silence(:stderr) do
39
+ action.run
40
+ end
41
+
42
+ expect(path_exists?('file')).to be_true
43
+ end
44
+
45
+ it 'creates sub directories' do
46
+ repository = double('TemplateRepository')
47
+ expect(repository).to receive(:find).with(:template)
48
+
49
+ data = double('Data')
50
+
51
+ engine_klass = Class.new do
52
+ def initialize(data)
53
+ end
54
+
55
+ def compile(template, destination)
56
+ end
57
+ end
58
+
59
+ action = Actions::CreateFile.new(:template, ::File.join(working_directory, 'data', 'file'), data, {create_directories: true}, engine_klass, repository)
60
+ silence(:stderr) do
61
+ action.run
62
+ end
63
+
64
+ expect(path_exists?('data/file')).to be_true
65
+ end
66
+ it 'respects existing path' do
67
+ repository = double('TemplateRepository')
68
+
69
+ data = double('Data')
70
+
71
+ engine_klass = Class.new do
72
+ def initialize(data)
73
+ end
74
+
75
+ def compile(template, destination)
76
+ end
77
+ end
78
+
79
+ file = create_file('file')
80
+ action = Actions::CreateFile.new(:template, file, data, {}, engine_klass, repository)
81
+ result = capture(:stderr) do
82
+ ProxyTester.ui_logger.level = :info
83
+ action.run
84
+ end
85
+
86
+ expect(result).to include('already')
87
+ end
88
+
89
+ it 'does not respect existing path if forced to' do
90
+ repository = double('TemplateRepository')
91
+ expect(repository).to receive(:find).with(:template)
92
+
93
+ data = double('Data')
94
+
95
+ engine_klass = Class.new do
96
+ def initialize(data)
97
+ end
98
+
99
+ def compile(template, destination)
100
+ end
101
+ end
102
+
103
+ file = create_file('file')
104
+ action = Actions::CreateFile.new(:template, file, data, { force: true }, engine_klass, repository)
105
+
106
+ result = capture(:stderr) do
107
+ ProxyTester.ui_logger.level = :info
108
+ action.run
109
+ end
110
+
111
+ expect(result).to include('Creating file')
112
+ end
113
+
114
+ it 'resolves ~' do
115
+ repository = double('TemplateRepository')
116
+ expect(repository).to receive(:find).with(:template)
117
+
118
+ data = double('Data')
119
+
120
+ engine_klass = Class.new do
121
+ def initialize(data)
122
+ end
123
+
124
+ def compile(template, destination)
125
+ end
126
+ end
127
+
128
+ action = with_environment 'HOME' => working_directory do
129
+ Actions::CreateFile.new(:template, '~/file', data, { force: true }, engine_klass, repository)
130
+ end
131
+
132
+ silence(:stderr) do
133
+ action.run
134
+ end
135
+
136
+ expect(path_exists?('file')).to be_true
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Actions::CreateOutput do
5
+ context '#initialize' do
6
+ it 'requires template, data and output' do
7
+ output = double('IO')
8
+ repository = double('TemplateRepository')
9
+ data = double('Data')
10
+
11
+ engine_klass = Class.new do
12
+ def initialize(data)
13
+ end
14
+
15
+ def compile(template, destination)
16
+ end
17
+ end
18
+
19
+ Actions::CreateOutput.new(:template, output, data, engine_klass, repository)
20
+ end
21
+ end
22
+
23
+ context '#run' do
24
+ it 'runs the action' do
25
+ output = double('$stdout')
26
+
27
+ repository = double('TemplateRepository')
28
+ expect(repository).to receive(:find).with(:template)
29
+
30
+ data = double('Data')
31
+
32
+ engine_klass = Class.new do
33
+ def initialize(data)
34
+ end
35
+
36
+ def compile(template, destination)
37
+ end
38
+ end
39
+
40
+ silence(:stderr) do
41
+ Actions::CreateOutput.new(:template, output, data, engine_klass, repository).run
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,74 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Actions::HandleError do
5
+ context '#initialize' do
6
+ it 'requires an exception' do
7
+ expect {
8
+ Actions::HandleError.new(StandardError.new)
9
+ }.not_to raise_error
10
+ end
11
+ end
12
+
13
+ context '#run' do
14
+ it 'handles errors' do
15
+ action = Actions::HandleError.new(RuntimeError.new)
16
+
17
+ silence(:stderr) do
18
+ begin
19
+ action.run
20
+ rescue SystemExit => e
21
+ @err = e
22
+ end
23
+ end
24
+
25
+ expect(@err).to be_kind_of(SystemExit)
26
+ expect(@err.status).to be(99)
27
+ end
28
+
29
+ it 'parses original message with json' do
30
+ action = Actions::HandleError.new(RuntimeError.new(JSON.dump(name: 'asdf')))
31
+
32
+ silence(:stderr) do
33
+ begin
34
+ action.run
35
+ rescue SystemExit => e
36
+ @err = e
37
+ end
38
+ end
39
+
40
+ expect(@err).to be_kind_of(SystemExit)
41
+ expect(@err.status).to be(99)
42
+ end
43
+
44
+ it 'returns an empty hash on parse error' do
45
+ action = Actions::HandleError.new(RuntimeError.new('asdf'))
46
+
47
+ silence(:stderr) do
48
+ begin
49
+ action.run
50
+ rescue SystemExit => e
51
+ @err = e
52
+ end
53
+ end
54
+
55
+ expect(@err).to be_kind_of(SystemExit)
56
+ expect(@err.status).to be(99)
57
+ end
58
+
59
+ it 'returns an empty hash if result is not a hash' do
60
+ action = Actions::HandleError.new(RuntimeError.new(JSON.dump(['asdf'])))
61
+
62
+ silence(:stderr) do
63
+ begin
64
+ action.run
65
+ rescue SystemExit => e
66
+ @err = e
67
+ end
68
+ end
69
+
70
+ expect(@err).to be_kind_of(SystemExit)
71
+ expect(@err.status).to be(99)
72
+ end
73
+ end
74
+ end