scripted 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.
- data/.gitignore +19 -0
- data/.rspec +3 -0
- data/.travis.yml +8 -0
- data/Gemfile +6 -0
- data/MIT-LICENSE +22 -0
- data/README.md +423 -0
- data/Rakefile +39 -0
- data/bin/scripted +67 -0
- data/cucumber.yml +3 -0
- data/examples/important.rb +31 -0
- data/examples/parallel.rb +30 -0
- data/examples/pride.rb +37 -0
- data/examples/websockets.png +0 -0
- data/examples/websockets.rb +37 -0
- data/examples/websockets/public/ansiparse.js +156 -0
- data/examples/websockets/server.rb +32 -0
- data/examples/websockets/server.ru +10 -0
- data/examples/websockets/views/_client.handlebars +47 -0
- data/examples/websockets/views/app.coffee +210 -0
- data/examples/websockets/views/index.erb +1 -0
- data/examples/websockets/views/layout.erb +14 -0
- data/examples/websockets/views/style.sass +61 -0
- data/features/controlling_exit_status.feature +124 -0
- data/features/formatters.feature +142 -0
- data/features/rake_integration.feature +86 -0
- data/features/running_commands_in_parallel.feature +27 -0
- data/features/running_from_command_line.feature +56 -0
- data/features/running_from_ruby.feature +38 -0
- data/features/running_groups.feature +39 -0
- data/features/specifying_which_commands_to_run.feature +122 -0
- data/features/steps/scripted_steps.rb +25 -0
- data/features/support/aruba.rb +5 -0
- data/features/support/env.rb +2 -0
- data/install +5 -0
- data/lib/scripted.rb +28 -0
- data/lib/scripted/command.rb +82 -0
- data/lib/scripted/commands/rake.rb +25 -0
- data/lib/scripted/commands/ruby.rb +22 -0
- data/lib/scripted/commands/shell.rb +28 -0
- data/lib/scripted/configuration.rb +103 -0
- data/lib/scripted/error.rb +13 -0
- data/lib/scripted/formatters/announcer.rb +39 -0
- data/lib/scripted/formatters/blank.rb +97 -0
- data/lib/scripted/formatters/default.rb +62 -0
- data/lib/scripted/formatters/human_status.rb +38 -0
- data/lib/scripted/formatters/stats.rb +38 -0
- data/lib/scripted/formatters/table.rb +99 -0
- data/lib/scripted/formatters/websocket.rb +137 -0
- data/lib/scripted/group.rb +49 -0
- data/lib/scripted/output/command_logger.rb +42 -0
- data/lib/scripted/output/logger.rb +139 -0
- data/lib/scripted/rake_task.rb +24 -0
- data/lib/scripted/runner.rb +19 -0
- data/lib/scripted/running/execute.rb +16 -0
- data/lib/scripted/running/run_command.rb +101 -0
- data/lib/scripted/running/run_commands.rb +98 -0
- data/lib/scripted/running/select_commands.rb +22 -0
- data/lib/scripted/version.rb +3 -0
- data/scripted.gemspec +35 -0
- data/scripted.rb +16 -0
- data/spec/scripted/command_spec.rb +72 -0
- data/spec/scripted/commands/ruby_spec.rb +10 -0
- data/spec/scripted/commands/shell_spec.rb +18 -0
- data/spec/scripted/configuration_spec.rb +50 -0
- data/spec/scripted/formatters/websocket_spec.rb +14 -0
- data/spec/scripted/group_spec.rb +49 -0
- data/spec/scripted/running/run_command_spec.rb +157 -0
- data/spec/scripted/running/run_commands_spec.rb +150 -0
- data/spec/scripted/running/select_commands_spec.rb +28 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/expect_to_receive.rb +17 -0
- data/spec/support/io_capture.rb +50 -0
- metadata +340 -0
@@ -0,0 +1,142 @@
|
|
1
|
+
Feature: Formatters
|
2
|
+
|
3
|
+
You can specify multiple formatters, similar to RSpec formatters.
|
4
|
+
|
5
|
+
This is done, either via the command line or via the configuration.
|
6
|
+
|
7
|
+
A formatter needs a name and optionally an output.
|
8
|
+
|
9
|
+
In the following example, the default output (the output of your commands)
|
10
|
+
will be written to the file `out.txt` but the announcer formatter will print
|
11
|
+
to the terminal.
|
12
|
+
|
13
|
+
$ scripted -f default -o out.txt -f announcer
|
14
|
+
|
15
|
+
To specify a formatter in the configuration:
|
16
|
+
|
17
|
+
``` ruby
|
18
|
+
formatter "default", :out => "out.txt"
|
19
|
+
formatter "announcer"
|
20
|
+
|
21
|
+
run "bundle install"
|
22
|
+
```
|
23
|
+
|
24
|
+
If you don't specify a format, only the default formatter will be used. If
|
25
|
+
you specify a formatter, the default won't be used, so you won't see any
|
26
|
+
output.
|
27
|
+
|
28
|
+
There are a couple of formatters included, such as `default`, `table`,
|
29
|
+
`announcer`, `websocket` and `stats`. If you want to add your own, just use
|
30
|
+
the complete class name as a formatter.
|
31
|
+
|
32
|
+
$ scripted -f MyAwesome::Formatter
|
33
|
+
|
34
|
+
Take a look at the included formatters to see how to make your own.
|
35
|
+
|
36
|
+
Scenario: Saving output to a file
|
37
|
+
Given the configuration:
|
38
|
+
"""
|
39
|
+
run "echo Hi there"
|
40
|
+
"""
|
41
|
+
When I run `scripted -f default -o output.txt`
|
42
|
+
Then the output should not contain "Hi there"
|
43
|
+
But the file "output.txt" should contain "Hi there"
|
44
|
+
|
45
|
+
Scenario: Multiple outputs
|
46
|
+
Given the configuration:
|
47
|
+
"""
|
48
|
+
run "echo Hello there"
|
49
|
+
"""
|
50
|
+
When I run `scripted -f default -o output.txt -f announcer -o announce.txt`
|
51
|
+
Then the file "output.txt" should contain "Hello there"
|
52
|
+
And the file "announce.txt" should contain:
|
53
|
+
|
54
|
+
"""
|
55
|
+
┌────────────────────────────────────────────────┐
|
56
|
+
│ echo Hello there │
|
57
|
+
└────────────────────────────────────────────────┘
|
58
|
+
"""
|
59
|
+
|
60
|
+
Scenario: Status table formatter
|
61
|
+
Given the configuration:
|
62
|
+
"""
|
63
|
+
run "true"
|
64
|
+
run "true"
|
65
|
+
run "false"
|
66
|
+
run "true"
|
67
|
+
"""
|
68
|
+
When I run `scripted -f table`
|
69
|
+
Then it should fail with:
|
70
|
+
"""
|
71
|
+
┌─────────┬─────────┬─────────┐
|
72
|
+
│ Command │ Runtime │ Status │
|
73
|
+
├─────────┼─────────┼─────────┤
|
74
|
+
"""
|
75
|
+
|
76
|
+
Scenario: Announcer formatter
|
77
|
+
Given the configuration:
|
78
|
+
"""
|
79
|
+
run "echo hi there"
|
80
|
+
"""
|
81
|
+
When I run `scripted -f announcer -f default`
|
82
|
+
Then the output should contain:
|
83
|
+
"""
|
84
|
+
┌────────────────────────────────────────────────┐
|
85
|
+
│ echo hi there │
|
86
|
+
└────────────────────────────────────────────────┘
|
87
|
+
|
88
|
+
hi there
|
89
|
+
"""
|
90
|
+
|
91
|
+
Scenario: Stats output
|
92
|
+
Given the configuration:
|
93
|
+
"""
|
94
|
+
run "echo hi there"
|
95
|
+
"""
|
96
|
+
When I run `scripted -f stats`
|
97
|
+
Then the output should contain:
|
98
|
+
"""
|
99
|
+
name,runtime,status
|
100
|
+
"""
|
101
|
+
|
102
|
+
Scenario: Custom formatter
|
103
|
+
Given a file named "my_awesome/formatter.rb" with:
|
104
|
+
"""
|
105
|
+
require 'scripted/formatters/blank'
|
106
|
+
module MyAwesome
|
107
|
+
class Formatter < Scripted::Formatters::Blank
|
108
|
+
|
109
|
+
def execute(command)
|
110
|
+
puts "I am now starting #{command.name}"
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
115
|
+
"""
|
116
|
+
And the configuration:
|
117
|
+
"""
|
118
|
+
run "true"
|
119
|
+
"""
|
120
|
+
When I run `scripted -f MyAwesome::Formatter -I .`
|
121
|
+
Then it should pass with:
|
122
|
+
"""
|
123
|
+
I am now starting true
|
124
|
+
"""
|
125
|
+
|
126
|
+
Scenario: Custom Formatter in the configuration
|
127
|
+
Given the configuration:
|
128
|
+
"""
|
129
|
+
require 'scripted/formatters/blank'
|
130
|
+
class MyFormatter < Scripted::Formatters::Blank
|
131
|
+
def execute(command)
|
132
|
+
puts "I am now starting #{command.name}"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
formatter MyFormatter
|
136
|
+
run "true"
|
137
|
+
"""
|
138
|
+
When I run `scripted`
|
139
|
+
Then it should pass with:
|
140
|
+
"""
|
141
|
+
I am now starting true
|
142
|
+
"""
|
@@ -0,0 +1,86 @@
|
|
1
|
+
Feature: Rake Integration
|
2
|
+
|
3
|
+
Scripted has support for Rake.
|
4
|
+
|
5
|
+
You can either let it pick up your "scripted.rb" file, or define the commands
|
6
|
+
in place.
|
7
|
+
|
8
|
+
When you don't specify a block, it will pick up your "scripted.rb" file:
|
9
|
+
|
10
|
+
``` ruby
|
11
|
+
require 'scripted/rake_task'
|
12
|
+
Scripted::RakeTask.new(:scripted)
|
13
|
+
```
|
14
|
+
|
15
|
+
When you specify a block, it will use this block to execute:
|
16
|
+
|
17
|
+
``` ruby
|
18
|
+
require 'scripted/rake_task'
|
19
|
+
Scripted::RakeTask.new(:scripted) do
|
20
|
+
run "echo from inside rakefile"
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
The rake command will run the default group by default. To change this, specify the group:
|
25
|
+
|
26
|
+
``` ruby
|
27
|
+
require 'scripted/rake_task'
|
28
|
+
Scripted::RakeTask.new(:install, :install)
|
29
|
+
```
|
30
|
+
|
31
|
+
You can also specify Rake dependencies:
|
32
|
+
|
33
|
+
``` ruby
|
34
|
+
require 'scripted/rake_task'
|
35
|
+
Scripted::RakeTask.new(:my_task => "db:migrate")
|
36
|
+
```
|
37
|
+
|
38
|
+
Scenario: Picking up scripted.rb
|
39
|
+
|
40
|
+
Given a file named "scripted.rb" with:
|
41
|
+
"""
|
42
|
+
run "echo command 1"
|
43
|
+
"""
|
44
|
+
|
45
|
+
And a file named "Rakefile" with:
|
46
|
+
"""
|
47
|
+
require 'scripted/rake_task'
|
48
|
+
Scripted::RakeTask.new(:scripted)
|
49
|
+
"""
|
50
|
+
|
51
|
+
When I run `rake scripted`
|
52
|
+
Then the output should contain "command 1"
|
53
|
+
|
54
|
+
Scenario: Specifying different groups
|
55
|
+
|
56
|
+
Given a file named "scripted.rb" with:
|
57
|
+
"""
|
58
|
+
run "echo command 1"
|
59
|
+
group :install do
|
60
|
+
run "echo install command"
|
61
|
+
end
|
62
|
+
"""
|
63
|
+
|
64
|
+
And a file named "Rakefile" with:
|
65
|
+
"""
|
66
|
+
require 'scripted/rake_task'
|
67
|
+
Scripted::RakeTask.new(:scripted, :install)
|
68
|
+
"""
|
69
|
+
|
70
|
+
When I run `rake scripted`
|
71
|
+
Then the output should contain "install command"
|
72
|
+
But the output should not contain "command 1"
|
73
|
+
|
74
|
+
|
75
|
+
Scenario: Configuring in place
|
76
|
+
|
77
|
+
Given a file named "Rakefile" with:
|
78
|
+
"""
|
79
|
+
require 'scripted/rake_task'
|
80
|
+
Scripted::RakeTask.new(:scripted) do
|
81
|
+
run "echo from inside rakefile"
|
82
|
+
end
|
83
|
+
"""
|
84
|
+
And the file "scripted.rb" should not exist
|
85
|
+
When I run `rake scripted`
|
86
|
+
Then the output should contain "from inside rakefile"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: Running Commands in Parallel
|
2
|
+
|
3
|
+
Commands can be run in parallel. Simply put a `parallel` block around them.
|
4
|
+
|
5
|
+
``` ruby
|
6
|
+
parallel do
|
7
|
+
run "rspec"
|
8
|
+
run "cucumber"
|
9
|
+
end
|
10
|
+
```
|
11
|
+
|
12
|
+
Scenario: Parallel
|
13
|
+
|
14
|
+
Given the configuration:
|
15
|
+
"""
|
16
|
+
parallel do
|
17
|
+
run "sleep 1"
|
18
|
+
run "sleep 1"
|
19
|
+
end
|
20
|
+
parallel do
|
21
|
+
run "sleep 1"
|
22
|
+
run "sleep 1"
|
23
|
+
run "sleep 1"
|
24
|
+
end
|
25
|
+
"""
|
26
|
+
When I run `scripted -f table`
|
27
|
+
Then it should have taken about 2 seconds
|
@@ -0,0 +1,56 @@
|
|
1
|
+
Feature: Running from the Command Line
|
2
|
+
|
3
|
+
Scripted comes with a executable to run commands. This requires you to have
|
4
|
+
a configuration file somewhere. The default configuration file is
|
5
|
+
`scripted.rb`, allowing you to run scripted without passing any commands.
|
6
|
+
|
7
|
+
$ scripted
|
8
|
+
|
9
|
+
If you want to store your configuration file somewhere else,
|
10
|
+
you can specify it with the `-r` or `--require` option:
|
11
|
+
|
12
|
+
$ scripted -r foo.rb
|
13
|
+
|
14
|
+
To get more information, about the options, run:
|
15
|
+
|
16
|
+
$ scripted --help
|
17
|
+
|
18
|
+
Scenario: Running some commands
|
19
|
+
|
20
|
+
Given a file named "scripted.rb" with:
|
21
|
+
"""
|
22
|
+
run "echo command 1"
|
23
|
+
run "echo command 2"
|
24
|
+
"""
|
25
|
+
When I run `scripted`
|
26
|
+
Then it should pass
|
27
|
+
And the output should contain "command 1"
|
28
|
+
And the output should contain "command 2"
|
29
|
+
|
30
|
+
Scenario: By specifying another file
|
31
|
+
|
32
|
+
Given a file named "something_else.rb" with:
|
33
|
+
"""
|
34
|
+
run "echo 1"
|
35
|
+
run "echo 2"
|
36
|
+
"""
|
37
|
+
When I run `scripted -r something_else.rb`
|
38
|
+
Then it should pass
|
39
|
+
|
40
|
+
Scenario: With a non existing file
|
41
|
+
When I run `scripted -r nope.rb`
|
42
|
+
Then it should fail with regexp:
|
43
|
+
"""
|
44
|
+
^No such file -- .*nope.rb$
|
45
|
+
"""
|
46
|
+
|
47
|
+
Scenario: Without `scripted.rb`
|
48
|
+
When I run `scripted`
|
49
|
+
Then it should fail with regexp:
|
50
|
+
"""
|
51
|
+
^No such file -- .*scripted.rb$
|
52
|
+
"""
|
53
|
+
And the output should contain:
|
54
|
+
"""
|
55
|
+
Either create a file called 'scripted.rb', or specify another file to load
|
56
|
+
"""
|
@@ -0,0 +1,38 @@
|
|
1
|
+
Feature: Running from Ruby
|
2
|
+
|
3
|
+
If you want to use scripted from within your own Ruby application, you can
|
4
|
+
define and run your scripts in place.
|
5
|
+
|
6
|
+
Scenario: Configuring and running directly
|
7
|
+
|
8
|
+
Given a file named "app.rb" with:
|
9
|
+
"""
|
10
|
+
require 'scripted'
|
11
|
+
Scripted.run do
|
12
|
+
run "echo welcome from shell within Ruby"
|
13
|
+
end
|
14
|
+
"""
|
15
|
+
|
16
|
+
When I run `ruby app.rb`
|
17
|
+
Then the output should contain "welcome from shell within Ruby"
|
18
|
+
|
19
|
+
Scenario: Defining a configuration and running later
|
20
|
+
Given a file named "app.rb" with:
|
21
|
+
"""
|
22
|
+
require 'scripted'
|
23
|
+
|
24
|
+
configuration = Scripted.configure do
|
25
|
+
run "echo welcome from shell within Ruby"
|
26
|
+
end
|
27
|
+
|
28
|
+
puts "Not running yet at this point"
|
29
|
+
|
30
|
+
Scripted.run(configuration)
|
31
|
+
"""
|
32
|
+
|
33
|
+
When I run `ruby app.rb`
|
34
|
+
Then the output should contain:
|
35
|
+
"""
|
36
|
+
Not running yet at this point
|
37
|
+
welcome from shell within Ruby
|
38
|
+
"""
|
@@ -0,0 +1,39 @@
|
|
1
|
+
Feature: Running Groups
|
2
|
+
|
3
|
+
You can specify multiple groups and use the command line option "--group" or
|
4
|
+
"-g" to run only that group.
|
5
|
+
|
6
|
+
If you don't specify a group, it will run the default group. And if you don't
|
7
|
+
specify which group a command is in, it will be in the default group.
|
8
|
+
|
9
|
+
Example:
|
10
|
+
|
11
|
+
``` ruby
|
12
|
+
group :install do
|
13
|
+
run "bundle install"
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
Background:
|
18
|
+
Given the configuration:
|
19
|
+
"""
|
20
|
+
run "echo from the default group"
|
21
|
+
group :install do
|
22
|
+
run "echo from the install group"
|
23
|
+
end
|
24
|
+
"""
|
25
|
+
|
26
|
+
Scenario: Running the default group.
|
27
|
+
When I run `scripted`
|
28
|
+
Then the output should contain "from the default group"
|
29
|
+
But the output should not contain "from the install group"
|
30
|
+
|
31
|
+
Scenario: Running another group
|
32
|
+
When I run `scripted -g install`
|
33
|
+
Then the output should contain "from the install group"
|
34
|
+
But the output should not contain "from the default group"
|
35
|
+
|
36
|
+
Scenario: Running multiple groups
|
37
|
+
When I run `scripted -g install,default`
|
38
|
+
Then the output should contain "from the install group"
|
39
|
+
And the output should contain "from the default group"
|
@@ -0,0 +1,122 @@
|
|
1
|
+
Feature: Specifying which Command to Run
|
2
|
+
|
3
|
+
By default the name of the command is the shell command to be run.
|
4
|
+
|
5
|
+
There are a number of different runners.
|
6
|
+
|
7
|
+
* Shell commands (the default)
|
8
|
+
* Rake commands
|
9
|
+
* Ruby commands
|
10
|
+
|
11
|
+
Shell commands can be specified by using backticks, or the `sh` method:
|
12
|
+
|
13
|
+
``` ruby
|
14
|
+
run "javascript tests" do
|
15
|
+
`cucumber --tags @javascript`
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
Rake commands will try to run in the same process if you also happen to use
|
20
|
+
Rake integration. Otherwise it will just shell out.
|
21
|
+
|
22
|
+
``` ruby
|
23
|
+
run "migrations" do
|
24
|
+
rake "db:migrate"
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
Ruby commands will just execute a block. If you want to fail a ruby command,
|
29
|
+
just raise an exception.
|
30
|
+
|
31
|
+
``` ruby
|
32
|
+
run "version check" do
|
33
|
+
ruby do
|
34
|
+
fail "incorrect version" if Scripted::VERSION != "1.0"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
Scenario: Choosing a different shell command
|
40
|
+
|
41
|
+
Given the configuration:
|
42
|
+
"""
|
43
|
+
run "the name" do
|
44
|
+
sh "echo the command output"
|
45
|
+
end
|
46
|
+
"""
|
47
|
+
When I run `scripted`
|
48
|
+
Then the output should contain "the command output"
|
49
|
+
|
50
|
+
Scenario: Choosing a different shell command with backticks
|
51
|
+
|
52
|
+
Given the configuration:
|
53
|
+
"""
|
54
|
+
run "the name" do
|
55
|
+
`echo the command output`
|
56
|
+
end
|
57
|
+
"""
|
58
|
+
When I run `scripted`
|
59
|
+
Then the output should contain "the command output"
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
Scenario: Running a rake command outside rake
|
64
|
+
Given a file named "Rakefile" with:
|
65
|
+
"""
|
66
|
+
namespace :db do
|
67
|
+
task :migrate do
|
68
|
+
puts "the rake task ran"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
"""
|
72
|
+
And the configuration:
|
73
|
+
"""
|
74
|
+
run "rake" do
|
75
|
+
rake "db:migrate"
|
76
|
+
end
|
77
|
+
"""
|
78
|
+
When I run `scripted`
|
79
|
+
Then it should pass
|
80
|
+
And the output should contain "the rake task ran"
|
81
|
+
|
82
|
+
Scenario: Running a rake command from within Rake
|
83
|
+
|
84
|
+
If you are running rake inside rake, it will use the normal invocation
|
85
|
+
pattern, so dependencies will not be run again.
|
86
|
+
|
87
|
+
Given a file named "Rakefile" with:
|
88
|
+
"""
|
89
|
+
task :setup do
|
90
|
+
raise "setup ran again" if File.exist?("foo")
|
91
|
+
`touch foo`
|
92
|
+
end
|
93
|
+
task :migrate => :setup do
|
94
|
+
puts "the rake task ran"
|
95
|
+
end
|
96
|
+
require 'scripted/rake_task'
|
97
|
+
Scripted::RakeTask.new(:scripted => [:setup]) do
|
98
|
+
run "migrate" do
|
99
|
+
rake "migrate"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
task :both => [:setup, :scripted]
|
103
|
+
"""
|
104
|
+
When I run `rake both`
|
105
|
+
Then it should pass
|
106
|
+
Then the output should contain "the rake task ran"
|
107
|
+
|
108
|
+
Scenario: Running pure ruby
|
109
|
+
|
110
|
+
Given the configuration:
|
111
|
+
"""
|
112
|
+
run "some ruby code" do
|
113
|
+
ruby { puts "the command" }
|
114
|
+
end
|
115
|
+
run "some failing ruby code" do
|
116
|
+
ruby { raise "this command failed" }
|
117
|
+
end
|
118
|
+
"""
|
119
|
+
When I run `scripted`
|
120
|
+
Then it should fail
|
121
|
+
And the output should contain "the command"
|
122
|
+
And the output should contain "this command failed"
|