static-shell-templates 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ca91969fa6198bcbb7c23b35cdce42b83f772a2f
4
+ data.tar.gz: 792a224dea52fa5233d40b47dbaa2cfa4fd89010
5
+ SHA512:
6
+ metadata.gz: 12dda5a90c69c7e4121e4c858eab9424702b03189d51badb2c73ef67ac064f3bd164d0181be247a32dd9e20068d34da7ab17527f0f6dc3d9e647f6f3a87268bf
7
+ data.tar.gz: 817f30b3095cb22ef6df6a09d3c3544036ef9c164bd0ce135e760818e7fafac045ab75b3514e4a582a2f681f06a340b4a1593a64eac6aae7f143e72337d5d450
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .vagrant
16
+ _*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format Fuubar
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ require: rubocop-rspec
2
+ AllCops:
3
+ Exclude:
4
+ - '_builds/**/*'
5
+ - '_projects/**/*'
6
+ Style/Documentation:
7
+ Enabled: false
@@ -0,0 +1 @@
1
+ static-shell-templates
@@ -0,0 +1 @@
1
+ 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in static-shell-templates.gemspec
4
+ gemspec
@@ -0,0 +1,14 @@
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
+ require 'guard/rspec/dsl'
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ rspec = dsl.rspec
6
+ watch(rspec.spec_helper) { rspec.spec_dir }
7
+ watch(rspec.spec_support) { rspec.spec_dir }
8
+ watch(rspec.spec_files)
9
+
10
+ ruby = dsl.ruby
11
+ dsl.watch_spec_files_for(ruby.lib_files)
12
+ end
13
+
14
+ guard :rubocop, all_on_start: false
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Gonzalo Matheu
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,10 @@
1
+
2
+ test:
3
+ bats test/*.bats
4
+
5
+ bootstrap:
6
+ apt-get install -y git
7
+ git clone https://github.com/sstephenson/bats.git
8
+ cd bats && ./install.sh /usr/local
9
+
10
+ .PHONY: test bootstrap
@@ -0,0 +1,32 @@
1
+ # Static::Shell::Templates
2
+ [![wercker status](https://app.wercker.com/status/8d95c512321ca97cc536636bce512eb5/m "wercker status")](https://app.wercker.com/project/bykey/8d95c512321ca97cc536636bce512eb5)
3
+
4
+ TODO: Write a gem description
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'static-shell-templates'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install static-shell-templates
21
+
22
+ ## Usage
23
+
24
+ TODO: Write usage instructions here
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it ( https://github.com/[my-github-username]/static-shell-templates/fork )
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create a new Pull Request
@@ -0,0 +1,16 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RuboCop::RakeTask.new(:rubocop) do |task|
6
+ task.formatters = ['fuubar']
7
+ task.fail_on_error = false
8
+ end
9
+ RSpec::Core::RakeTask.new(:spec)
10
+
11
+ task default: [:spec, :rubocop]
12
+
13
+ desc 'Run interactive console'
14
+ task :console do
15
+ exec 'pry -Ilib -rstatic-shell-templates'
16
+ end
@@ -0,0 +1,20 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ WERCKER_CLI_URL = 'https://s3.amazonaws.com/downloads.wercker.com/cli/stable/linux_amd64/wercker'
5
+ Vagrant.configure(2) do |config|
6
+ config.vm.hostname = 'wercker'
7
+ config.vm.box = 'ubuntu/trusty64'
8
+
9
+ config.vm.network 'forwarded_port', guest: 12_375, host: 2375
10
+ config.vm.provision 'docker'
11
+ config.vm.provision 'shell', inline: <<-SHELL
12
+ sudo apt-get install -y curl vim
13
+ sudo curl -o /usr/local/bin/wercker #{WERCKER_CLI_URL}
14
+ sudo chmod +x /usr/local/bin/wercker
15
+ sudo cat > /etc/default/docker <<EOF
16
+ DOCKER_OPTS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"
17
+ EOF
18
+ sudo service docker restart
19
+ SHELL
20
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ require 'thor'
3
+ require 'static_shell_templates'
4
+
5
+ class Command < Thor
6
+ class_option :verbose, type: :boolean, aliases: '-v'
7
+
8
+ desc 'replace FILE', 'Outputs replaced template'
9
+ option :output, type: :string
10
+ def replace(file)
11
+ content = IO.read file
12
+ template = StaticShellTemplates::Template.new content
13
+ puts template.replace
14
+ rescue => error
15
+ puts "ERROR: #{error.message}"
16
+ puts error.backtrace if options[:verbose]
17
+ exit 1
18
+ end
19
+
20
+ desc 'version', 'Prints version'
21
+ def version
22
+ puts "StaticShellTemplates v#{StaticShellTemplates::VERSION}"
23
+ end
24
+ end
25
+
26
+ Command.start(ARGV)
@@ -0,0 +1,264 @@
1
+ #!/usr/bin/env bats
2
+
3
+ load test_helper
4
+ # fixtures bats
5
+
6
+ @test "show message" {
7
+ run bash build.sh
8
+ [ $status -eq 1 ]
9
+ [ $(expr "${lines[1]}" : "Linting all executables.*") -eq 0 ]
10
+ }
11
+
12
+ @test "error on sh_error" {
13
+ run bash build.sh
14
+ [ $status -eq 1 ]
15
+ [ $(expr "${lines[1]}" : "In .*sh_error.sh line 2.*") -ne 0 ]
16
+ }
17
+ #
18
+ # @test "-h and --help print help" {
19
+ # run bats -h
20
+ # [ $status -eq 0 ]
21
+ # [ "${#lines[@]}" -gt 3 ]
22
+ # }
23
+ #
24
+ # @test "invalid filename prints an error" {
25
+ # run bats nonexistent
26
+ # [ $status -eq 1 ]
27
+ # [ $(expr "$output" : ".*does not exist") -ne 0 ]
28
+ # }
29
+ #
30
+ # @test "empty test file runs zero tests" {
31
+ # run bats "$FIXTURE_ROOT/empty.bats"
32
+ # [ $status -eq 0 ]
33
+ # [ "$output" = "1..0" ]
34
+ # }
35
+ #
36
+ # @test "one passing test" {
37
+ # run bats "$FIXTURE_ROOT/passing.bats"
38
+ # [ $status -eq 0 ]
39
+ # [ "${lines[0]}" = "1..1" ]
40
+ # [ "${lines[1]}" = "ok 1 a passing test" ]
41
+ # }
42
+ #
43
+ # @test "summary passing tests" {
44
+ # run filter_control_sequences bats -p $FIXTURE_ROOT/passing.bats
45
+ # [ $status -eq 0 ]
46
+ # [ "${lines[1]}" = "1 test, 0 failures" ]
47
+ # }
48
+ #
49
+ # @test "summary passing and skipping tests" {
50
+ # run filter_control_sequences bats -p $FIXTURE_ROOT/passing_and_skipping.bats
51
+ # [ $status -eq 0 ]
52
+ # [ "${lines[2]}" = "2 tests, 0 failures, 1 skipped" ]
53
+ # }
54
+ #
55
+ # @test "summary passing and failing tests" {
56
+ # run filter_control_sequences bats -p $FIXTURE_ROOT/failing_and_passing.bats
57
+ # [ $status -eq 0 ]
58
+ # [ "${lines[4]}" = "2 tests, 1 failure" ]
59
+ # }
60
+ #
61
+ # @test "summary passing, failing and skipping tests" {
62
+ # run filter_control_sequences bats -p $FIXTURE_ROOT/passing_failing_and_skipping.bats
63
+ # [ $status -eq 0 ]
64
+ # [ "${lines[5]}" = "3 tests, 1 failure, 1 skipped" ]
65
+ # }
66
+ #
67
+ # @test "one failing test" {
68
+ # run bats "$FIXTURE_ROOT/failing.bats"
69
+ # [ $status -eq 1 ]
70
+ # [ "${lines[0]}" = '1..1' ]
71
+ # [ "${lines[1]}" = 'not ok 1 a failing test' ]
72
+ # [ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing.bats, line 4)" ]
73
+ # [ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed" ]
74
+ # }
75
+ #
76
+ # @test "one failing and one passing test" {
77
+ # run bats "$FIXTURE_ROOT/failing_and_passing.bats"
78
+ # [ $status -eq 1 ]
79
+ # [ "${lines[0]}" = '1..2' ]
80
+ # [ "${lines[1]}" = 'not ok 1 a failing test' ]
81
+ # [ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing_and_passing.bats, line 2)" ]
82
+ # [ "${lines[3]}" = "# \`false' failed" ]
83
+ # [ "${lines[4]}" = 'ok 2 a passing test' ]
84
+ # }
85
+ #
86
+ # @test "failing test with significant status" {
87
+ # STATUS=2 run bats "$FIXTURE_ROOT/failing.bats"
88
+ # [ $status -eq 1 ]
89
+ # [ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed with status 2" ]
90
+ # }
91
+ #
92
+ # @test "failing helper function logs the test case's line number" {
93
+ # run bats "$FIXTURE_ROOT/failing_helper.bats"
94
+ # [ $status -eq 1 ]
95
+ # [ "${lines[1]}" = 'not ok 1 failing helper function' ]
96
+ # [ "${lines[2]}" = "# (from function \`failing_helper' in file $RELATIVE_FIXTURE_ROOT/test_helper.bash, line 6," ]
97
+ # [ "${lines[3]}" = "# in test file $RELATIVE_FIXTURE_ROOT/failing_helper.bats, line 5)" ]
98
+ # [ "${lines[4]}" = "# \`failing_helper' failed" ]
99
+ # }
100
+ #
101
+ # @test "test environments are isolated" {
102
+ # run bats "$FIXTURE_ROOT/environment.bats"
103
+ # [ $status -eq 0 ]
104
+ # }
105
+ #
106
+ # @test "setup is run once before each test" {
107
+ # rm -f "$TMP/setup.log"
108
+ # run bats "$FIXTURE_ROOT/setup.bats"
109
+ # [ $status -eq 0 ]
110
+ # run cat "$TMP/setup.log"
111
+ # [ ${#lines[@]} -eq 3 ]
112
+ # }
113
+ #
114
+ # @test "teardown is run once after each test, even if it fails" {
115
+ # rm -f "$TMP/teardown.log"
116
+ # run bats "$FIXTURE_ROOT/teardown.bats"
117
+ # [ $status -eq 1 ]
118
+ # run cat "$TMP/teardown.log"
119
+ # [ ${#lines[@]} -eq 3 ]
120
+ # }
121
+ #
122
+ # @test "setup failure" {
123
+ # run bats "$FIXTURE_ROOT/failing_setup.bats"
124
+ # [ $status -eq 1 ]
125
+ # [ "${lines[1]}" = 'not ok 1 truth' ]
126
+ # [ "${lines[2]}" = "# (from function \`setup' in test file $RELATIVE_FIXTURE_ROOT/failing_setup.bats, line 2)" ]
127
+ # [ "${lines[3]}" = "# \`false' failed" ]
128
+ # }
129
+ #
130
+ # @test "passing test with teardown failure" {
131
+ # PASS=1 run bats "$FIXTURE_ROOT/failing_teardown.bats"
132
+ # [ $status -eq 1 ]
133
+ # [ "${lines[1]}" = 'not ok 1 truth' ]
134
+ # [ "${lines[2]}" = "# (from function \`teardown' in test file $RELATIVE_FIXTURE_ROOT/failing_teardown.bats, line 2)" ]
135
+ # [ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed" ]
136
+ # }
137
+ #
138
+ # @test "failing test with teardown failure" {
139
+ # PASS=0 run bats "$FIXTURE_ROOT/failing_teardown.bats"
140
+ # [ $status -eq 1 ]
141
+ # [ "${lines[1]}" = 'not ok 1 truth' ]
142
+ # [ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing_teardown.bats, line 6)" ]
143
+ # [ "${lines[3]}" = $'# `[ "$PASS" = "1" ]\' failed' ]
144
+ # }
145
+ #
146
+ # @test "teardown failure with significant status" {
147
+ # PASS=1 STATUS=2 run bats "$FIXTURE_ROOT/failing_teardown.bats"
148
+ # [ $status -eq 1 ]
149
+ # [ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed with status 2" ]
150
+ # }
151
+ #
152
+ # @test "failing test file outside of BATS_CWD" {
153
+ # cd "$TMP"
154
+ # run bats "$FIXTURE_ROOT/failing.bats"
155
+ # [ $status -eq 1 ]
156
+ # [ "${lines[2]}" = "# (in test file $FIXTURE_ROOT/failing.bats, line 4)" ]
157
+ # }
158
+ #
159
+ # @test "load sources scripts relative to the current test file" {
160
+ # run bats "$FIXTURE_ROOT/load.bats"
161
+ # [ $status -eq 0 ]
162
+ # }
163
+ #
164
+ # @test "load aborts if the specified script does not exist" {
165
+ # HELPER_NAME="nonexistent" run bats "$FIXTURE_ROOT/load.bats"
166
+ # [ $status -eq 1 ]
167
+ # }
168
+ #
169
+ # @test "load sources scripts by absolute path" {
170
+ # HELPER_NAME="${FIXTURE_ROOT}/test_helper.bash" run bats "$FIXTURE_ROOT/load.bats"
171
+ # [ $status -eq 0 ]
172
+ # }
173
+ #
174
+ # @test "load aborts if the script, specified by an absolute path, does not exist" {
175
+ # HELPER_NAME="${FIXTURE_ROOT}/nonexistent" run bats "$FIXTURE_ROOT/load.bats"
176
+ # [ $status -eq 1 ]
177
+ # }
178
+ #
179
+ # @test "output is discarded for passing tests and printed for failing tests" {
180
+ # run bats "$FIXTURE_ROOT/output.bats"
181
+ # [ $status -eq 1 ]
182
+ # [ "${lines[6]}" = '# failure stdout 1' ]
183
+ # [ "${lines[7]}" = '# failure stdout 2' ]
184
+ # [ "${lines[11]}" = '# failure stderr' ]
185
+ # }
186
+ #
187
+ # @test "-c prints the number of tests" {
188
+ # run bats -c "$FIXTURE_ROOT/empty.bats"
189
+ # [ $status -eq 0 ]
190
+ # [ "$output" = "0" ]
191
+ #
192
+ # run bats -c "$FIXTURE_ROOT/output.bats"
193
+ # [ $status -eq 0 ]
194
+ # [ "$output" = "4" ]
195
+ # }
196
+ #
197
+ # @test "dash-e is not mangled on beginning of line" {
198
+ # run bats "$FIXTURE_ROOT/intact.bats"
199
+ # [ $status -eq 0 ]
200
+ # [ "${lines[1]}" = "ok 1 dash-e on beginning of line" ]
201
+ # }
202
+ #
203
+ # @test "dos line endings are stripped before testing" {
204
+ # run bats "$FIXTURE_ROOT/dos_line.bats"
205
+ # [ $status -eq 0 ]
206
+ # }
207
+ #
208
+ # @test "test file without trailing newline" {
209
+ # run bats "$FIXTURE_ROOT/without_trailing_newline.bats"
210
+ # [ $status -eq 0 ]
211
+ # [ "${lines[1]}" = "ok 1 truth" ]
212
+ # }
213
+ #
214
+ # @test "skipped tests" {
215
+ # run bats "$FIXTURE_ROOT/skipped.bats"
216
+ # [ $status -eq 0 ]
217
+ # [ "${lines[1]}" = "ok 1 # skip a skipped test" ]
218
+ # [ "${lines[2]}" = "ok 2 # skip (a reason) a skipped test with a reason" ]
219
+ # }
220
+ #
221
+ # @test "extended syntax" {
222
+ # run bats-exec-test -x "$FIXTURE_ROOT/failing_and_passing.bats"
223
+ # [ $status -eq 1 ]
224
+ # [ "${lines[1]}" = 'begin 1 a failing test' ]
225
+ # [ "${lines[2]}" = 'not ok 1 a failing test' ]
226
+ # [ "${lines[5]}" = 'begin 2 a passing test' ]
227
+ # [ "${lines[6]}" = 'ok 2 a passing test' ]
228
+ # }
229
+ #
230
+ # @test "pretty and tap formats" {
231
+ # run bats --tap "$FIXTURE_ROOT/passing.bats"
232
+ # tap_output="$output"
233
+ # [ $status -eq 0 ]
234
+ #
235
+ # run bats --pretty "$FIXTURE_ROOT/passing.bats"
236
+ # pretty_output="$output"
237
+ # [ $status -eq 0 ]
238
+ #
239
+ # [ "$tap_output" != "$pretty_output" ]
240
+ # }
241
+ #
242
+ # @test "pretty formatter bails on invalid tap" {
243
+ # run bats --tap "$FIXTURE_ROOT/invalid_tap.bats"
244
+ # [ $status -eq 1 ]
245
+ # [ "${lines[0]}" = "This isn't TAP!" ]
246
+ # [ "${lines[1]}" = "Good day to you" ]
247
+ # }
248
+ #
249
+ # @test "single-line tests" {
250
+ # run bats "$FIXTURE_ROOT/single_line.bats"
251
+ # [ $status -eq 1 ]
252
+ # [ "${lines[1]}" = 'ok 1 empty' ]
253
+ # [ "${lines[2]}" = 'ok 2 passing' ]
254
+ # [ "${lines[3]}" = 'ok 3 input redirection' ]
255
+ # [ "${lines[4]}" = 'not ok 4 failing' ]
256
+ # [ "${lines[5]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/single_line.bats, line 9)" ]
257
+ # [ "${lines[6]}" = $'# `@test "failing" { false; }\' failed' ]
258
+ # }
259
+ #
260
+ # @test "testing IFS not modified by run" {
261
+ # run bats "$FIXTURE_ROOT/loop_keep_IFS.bats"
262
+ # [ $status -eq 0 ]
263
+ # [ "${lines[1]}" = "ok 1 loop_func" ]
264
+ # }
@@ -0,0 +1,6 @@
1
+ #! /bin/bash
2
+ #template: source: https://gist.githubusercontent.com/gmatheu/302aec1e3afb254bde8b/raw/857da1981e3ab2234ac7bd48fbce13eb10ef40dc/log-functions
3
+
4
+ echo $(type info)
5
+ info "TEST"
6
+
@@ -0,0 +1,8 @@
1
+ #! /bin/bash
2
+ #template: source: https://gist.githubusercontent.com/gmatheu/302aec1e3afb254bde8b/raw/857da1981e3ab2234ac7bd48fbce13eb10ef40dc/log-functions
3
+ info() {
4
+ echo "NOTHING"
5
+ }
6
+ #template:end
7
+ info "TEST"
8
+
@@ -0,0 +1,61 @@
1
+ require 'net/http'
2
+ require 'logger'
3
+ require 'static_shell_templates/version'
4
+
5
+ module StaticShellTemplates
6
+ class Template
7
+ OPENING = '#template: '
8
+ CLOSING = '#template:end'
9
+
10
+ def initialize(content, verbose: false)
11
+ @content = content
12
+ @logger = Logger.new(STDOUT)
13
+ @verbose = verbose
14
+ end
15
+
16
+ def replace
17
+ delete_end_end(includes.reduce(@content) do |memo, inc|
18
+ memo.gsub(inc.template, inc.output)
19
+ end)
20
+ end
21
+
22
+ def delete_end_end(content)
23
+ content.gsub(/#{CLOSING}.*#{CLOSING}/m, CLOSING)
24
+ end
25
+
26
+ def includes
27
+ @content.scan(/#{OPENING}.*$/).map do |tpl|
28
+ Include.new tpl, @logger
29
+ end
30
+ end
31
+ end
32
+
33
+ class Include
34
+ attr_reader :source, :template, :header
35
+
36
+ def initialize(template, logger = Logger.new(STDOUT))
37
+ @template = template
38
+ @header = template
39
+ @logger = logger
40
+ # @logger.debug template
41
+ source_match = template.match(/source: (?<source>.*)/)
42
+ @source = URI source_match['source']
43
+ end
44
+
45
+ def content
46
+ response = Net::HTTP.get_response @source
47
+ fail Error, "Content not found: #{@source}" if response.code != '200'
48
+
49
+ response.body
50
+ end
51
+
52
+ def output
53
+ %(#{@header}
54
+ #{content}
55
+ #template:end)
56
+ end
57
+ end
58
+
59
+ class Error < RuntimeError
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module StaticShellTemplates
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'webmock/rspec'
2
+ require 'static_shell_templates'
3
+
4
+ RSpec.configure do |config|
5
+ config.expect_with :rspec do |expectations|
6
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
7
+ end
8
+
9
+ config.mock_with :rspec do |mocks|
10
+ mocks.verify_partial_doubles = true
11
+ end
12
+ end
@@ -0,0 +1,34 @@
1
+ describe StaticShellTemplates::Include do
2
+ describe '#content' do
3
+ context 'from url' do
4
+ let(:include_url) { 'https://gist.test.com/path' }
5
+ let(:include_content) do
6
+ %q|info() {
7
+ echo "INFO: $1"
8
+ }|
9
+ end
10
+
11
+ before :each do
12
+ stub_request(:get, include_url)
13
+ .to_return(body: include_content, status: 200)
14
+ end
15
+
16
+ let(:include) { described_class.new "#template: source: #{include_url}" }
17
+ subject(:content) { include.content }
18
+
19
+ it { is_expected.to eq include_content }
20
+ end
21
+
22
+ context 'non existing url' do
23
+ let(:url) { 'http://dont.com' }
24
+ let(:include) { described_class.new "#template: source: #{url}" }
25
+
26
+ it 'raise error' do
27
+ stub_request(:get, url)
28
+ .to_return(status: 404)
29
+
30
+ expect { include.content }.to raise_error(StaticShellTemplates::Error)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,99 @@
1
+ describe StaticShellTemplates::Template do
2
+ describe '#replace' do
3
+ context 'no templates' do
4
+ let(:content) do
5
+ %(
6
+ #! bin/bash
7
+ echo "TEST")
8
+ end
9
+ let(:template) { described_class.new content }
10
+ subject(:output) { template.replace }
11
+
12
+ it { is_expected.to eq content }
13
+
14
+ it 'has no includes' do
15
+ expect(template.includes.size).to eq 0
16
+ end
17
+ end
18
+
19
+ context 'basic templates' do
20
+ let(:url) { 'http://mock-url.com/path' }
21
+ let(:url_content) { 'CONTENT' }
22
+ let(:content) do
23
+ %(#! bin/bash
24
+ #template: source: #{url}
25
+ echo "TEST")
26
+ end
27
+ let(:template) { described_class.new content }
28
+ let(:expected_output) do
29
+ %(#! bin/bash
30
+ #template: source: #{url}
31
+ #{url_content}
32
+ #template:end
33
+ echo "TEST")
34
+ end
35
+
36
+ before :each do
37
+ stub_request(:get, url)
38
+ .to_return(body: url_content, status: 200)
39
+ end
40
+
41
+ subject(:output) { template.replace }
42
+ it { is_expected.to eq expected_output }
43
+
44
+ describe '#includes' do
45
+ let(:includes) { template.includes }
46
+ subject(:include) { includes.first }
47
+
48
+ it 'detects includes' do
49
+ expect(includes.size).to eq 1
50
+ end
51
+
52
+ it 'source is url' do
53
+ expect(include.source).to eq URI(url)
54
+ end
55
+ end
56
+ end
57
+
58
+ context 'existing templates' do
59
+ let(:url) { 'http://mock-url.com/path' }
60
+ let(:url_content) { 'CONTENT' }
61
+ let(:content) do
62
+ %(#! bin/bash
63
+ #template: source: #{url}
64
+ OLD STUFF
65
+ #template:end
66
+ echo "TEST")
67
+ end
68
+ let(:template) { described_class.new content }
69
+ let(:expected_output) do
70
+ %(#! bin/bash
71
+ #template: source: #{url}
72
+ #{url_content}
73
+ #template:end
74
+ echo "TEST")
75
+ end
76
+
77
+ before :each do
78
+ stub_request(:get, url)
79
+ .to_return(body: url_content, status: 200)
80
+ end
81
+
82
+ subject(:output) { template.replace }
83
+ it { is_expected.to eq expected_output }
84
+
85
+ describe '#includes' do
86
+ let(:includes) { template.includes }
87
+ subject(:include) { includes.first }
88
+
89
+ it 'detects includes' do
90
+ expect(includes.size).to eq 1
91
+ end
92
+
93
+ it 'source is url' do
94
+ expect(include.source).to eq URI(url)
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'static_shell_templates/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'static-shell-templates'
8
+ spec.version = StaticShellTemplates::VERSION
9
+ spec.authors = ['Gonzalo Matheu']
10
+ spec.email = ['gonzalommj@gmail.com']
11
+ spec.summary = 'static shell templates'
12
+ spec.description = 'static shell templates'
13
+ spec.homepage = ''
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_dependency 'thor'
22
+ spec.add_development_dependency 'bundler', '~> 1.7'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'pry'
25
+ spec.add_development_dependency 'pry-coolline'
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'fuubar'
28
+ spec.add_development_dependency 'guard'
29
+ spec.add_development_dependency 'rubocop'
30
+ spec.add_development_dependency 'rubocop-rspec'
31
+ spec.add_development_dependency 'guard-rspec'
32
+ spec.add_development_dependency 'guard-rubocop'
33
+ spec.add_development_dependency 'webmock'
34
+ spec.add_development_dependency 'pry-byebug'
35
+ end
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env bats
2
+
3
+ # load test_helper
4
+
5
+ @test "replace when does not exist" {
6
+ run bash -c 'bundle exec static_shell_templates replace examples/basic.sh | bash'
7
+
8
+ echo "${lines[@]}"
9
+ [ $status = 0 ]
10
+ [[ ${lines[0]} =~ "info () {" ]]
11
+ [[ ${lines[1]} =~ "INFO: TEST" ]]
12
+ }
13
+
14
+ @test "update when already exist" {
15
+ run bash -c 'bundle exec static_shell_templates replace examples/existing.sh | bash'
16
+
17
+ echo "${lines[@]}"
18
+ [ $status = 0 ]
19
+ [[ ${lines[0]} =~ "INFO: TEST" ]]
20
+ }
21
+
@@ -0,0 +1,18 @@
1
+ box: ruby
2
+ build:
3
+ steps:
4
+ - script:
5
+ name: Bootstrap
6
+ code: make bootstrap
7
+ - script:
8
+ name: Bundle Install
9
+ code: bundle install
10
+ - script:
11
+ name: Tests
12
+ code: bundle exec rake
13
+ - script:
14
+ name: Linting
15
+ code: bundle exec rake rubocop
16
+ - script:
17
+ name: E2E
18
+ code: make test
metadata ADDED
@@ -0,0 +1,269 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: static-shell-templates
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gonzalo Matheu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-coolline
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: fuubar
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: guard-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: guard-rubocop
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: webmock
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: pry-byebug
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ description: static shell templates
210
+ email:
211
+ - gonzalommj@gmail.com
212
+ executables:
213
+ - static_shell_templates
214
+ extensions: []
215
+ extra_rdoc_files: []
216
+ files:
217
+ - ".gitignore"
218
+ - ".rspec"
219
+ - ".rubocop.yml"
220
+ - ".ruby-gemset"
221
+ - ".ruby-version"
222
+ - Gemfile
223
+ - Guardfile
224
+ - LICENSE.txt
225
+ - Makefile
226
+ - README.md
227
+ - Rakefile
228
+ - Vagrantfile
229
+ - bin/static_shell_templates
230
+ - build.bats
231
+ - examples/basic.sh
232
+ - examples/existing.sh
233
+ - lib/static_shell_templates.rb
234
+ - lib/static_shell_templates/version.rb
235
+ - spec/spec_helper.rb
236
+ - spec/static_shell_templates/include_spec.rb
237
+ - spec/static_shell_templates/template_spec.rb
238
+ - static-shell-templates.gemspec
239
+ - test/simple.bats
240
+ - wercker.yml
241
+ homepage: ''
242
+ licenses:
243
+ - MIT
244
+ metadata: {}
245
+ post_install_message:
246
+ rdoc_options: []
247
+ require_paths:
248
+ - lib
249
+ required_ruby_version: !ruby/object:Gem::Requirement
250
+ requirements:
251
+ - - ">="
252
+ - !ruby/object:Gem::Version
253
+ version: '0'
254
+ required_rubygems_version: !ruby/object:Gem::Requirement
255
+ requirements:
256
+ - - ">="
257
+ - !ruby/object:Gem::Version
258
+ version: '0'
259
+ requirements: []
260
+ rubyforge_project:
261
+ rubygems_version: 2.4.8
262
+ signing_key:
263
+ specification_version: 4
264
+ summary: static shell templates
265
+ test_files:
266
+ - spec/spec_helper.rb
267
+ - spec/static_shell_templates/include_spec.rb
268
+ - spec/static_shell_templates/template_spec.rb
269
+ - test/simple.bats