baf 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/baf.rb +11 -0
- data/lib/baf/cli.rb +71 -0
- data/lib/baf/env.rb +10 -0
- data/lib/baf/option_registrant.rb +34 -0
- data/lib/baf/testing/cucumber.rb +5 -0
- data/lib/baf/testing/cucumber/steps/execution.rb +38 -0
- data/lib/baf/testing/cucumber/steps/output.rb +22 -0
- data/lib/baf/version.rb +3 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fdbb678fca1424651ded0c54c5983915b3ca7d04
|
4
|
+
data.tar.gz: bd7557646c1eff5b19daa9aa6f21b3cd9cd49953
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7385fda52a9b80301c0b5fdfd5bb3fb732debcde8d7aee68f5eb77c129f96052d3b93a1df938b73546126d374cc55e1f0fd7f0f9fabd560b7c0e9f2bbc72cc76
|
7
|
+
data.tar.gz: d487f12253679abf4b5b7bef4c6c3fdb3b266aae1fbcae2ccdcb4b32eaf544cb7d61709a59a2867ea393031f8d1906d37a8e176acfb6389fce31e25de64c4611
|
data/lib/baf.rb
ADDED
data/lib/baf/cli.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
module Baf
|
2
|
+
class CLI
|
3
|
+
ArgumentError = Class.new(ArgumentError)
|
4
|
+
|
5
|
+
EX_USAGE = 64
|
6
|
+
EX_SOFTWARE = 70
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def flag *args, registrant: OptionRegistrant
|
10
|
+
registrant.register_flag env, option_parser, *args
|
11
|
+
end
|
12
|
+
|
13
|
+
def option *args, registrant: OptionRegistrant
|
14
|
+
registrant.register_option env, option_parser, Option.new(*args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def run arguments, stdout: $stdout, stderr: $stderr
|
18
|
+
cli = new env(stdout), option_parser, arguments
|
19
|
+
cli.parse_arguments!
|
20
|
+
cli.run
|
21
|
+
rescue ArgumentError => e
|
22
|
+
stderr.puts e
|
23
|
+
exit EX_USAGE
|
24
|
+
rescue StandardError => e
|
25
|
+
stderr.puts "#{e.class.name}: #{e}"
|
26
|
+
stderr.puts e.backtrace.map { |l| ' %s' % l }
|
27
|
+
exit EX_SOFTWARE
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
Option = Struct.new('Option', :short, :long, :arg, :desc)
|
33
|
+
|
34
|
+
def env output = nil
|
35
|
+
@env ||= Env.new(output)
|
36
|
+
end
|
37
|
+
|
38
|
+
def option_parser
|
39
|
+
@option_parser ||= OptionParser.new
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
attr_reader :arguments, :env, :option_parser
|
44
|
+
|
45
|
+
def initialize env, option_parser, arguments
|
46
|
+
@env = env
|
47
|
+
@option_parser = option_parser
|
48
|
+
@arguments = arguments
|
49
|
+
setup_default_options option_parser
|
50
|
+
end
|
51
|
+
|
52
|
+
def parse_arguments!
|
53
|
+
option_parser.parse! arguments
|
54
|
+
rescue OptionParser::InvalidOption
|
55
|
+
raise ArgumentError, option_parser
|
56
|
+
end
|
57
|
+
|
58
|
+
def run
|
59
|
+
end
|
60
|
+
|
61
|
+
protected
|
62
|
+
|
63
|
+
def setup_default_options option_parser
|
64
|
+
option_parser.separator ''
|
65
|
+
option_parser.separator 'options:'
|
66
|
+
option_parser.on_tail '-h', '--help', 'print this message' do
|
67
|
+
env.print option_parser
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/baf/env.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Baf
|
2
|
+
class OptionRegistrant
|
3
|
+
class << self
|
4
|
+
def register_flag env, parser, short, long
|
5
|
+
define_env_flag env, long
|
6
|
+
parser.on "-#{short}", "--#{long}", "enable #{long} mode" do
|
7
|
+
env.send :"#{long}=", true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def register_option env, parser, opt
|
12
|
+
define_env_accessor env, opt.long
|
13
|
+
parser.on "-#{opt.short}", "--#{opt.long} #{opt.arg}", opt.desc do |v|
|
14
|
+
env.send :"#{opt.long}=", v
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def define_env_accessor env, name
|
21
|
+
(class << env; self end).send :attr_accessor, name
|
22
|
+
end
|
23
|
+
|
24
|
+
def define_env_flag env, name
|
25
|
+
define_env_accessor env, name
|
26
|
+
env.send :"#{name}=", false
|
27
|
+
env.define_singleton_method :"#{name}?" do
|
28
|
+
instance_variable_get :"@#{name}"
|
29
|
+
end
|
30
|
+
env.instance_variable_set :"@#{name}", false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
def program_run check: false, opts: nil, args: nil
|
2
|
+
cmd = %w[ruby baf]
|
3
|
+
cmd << opts if opts
|
4
|
+
cmd << args.split(' ') if args
|
5
|
+
run_simple cmd.join(' '), fail_on_error: false
|
6
|
+
program_run_check if check
|
7
|
+
end
|
8
|
+
|
9
|
+
def program_run_check status: 0
|
10
|
+
expect(last_command_started).to have_exit_status status
|
11
|
+
rescue RSpec::Expectations::ExpectationNotMetError => e
|
12
|
+
if ENV.key? 'BAF_TEST_DEBUG'
|
13
|
+
fail RSpec::Expectations::ExpectationNotMetError, <<-eoh
|
14
|
+
#{e.message} Output was:
|
15
|
+
```\n#{last_command_started.output.lines.map { |l| " #{l}" }.join} ```
|
16
|
+
eoh
|
17
|
+
else
|
18
|
+
raise
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
When /^I( successfully)? run the program$/ do |check|
|
24
|
+
program_run check: !!check
|
25
|
+
end
|
26
|
+
|
27
|
+
When /^I( successfully)? run the program with arguments (.+)$/ do |check, args|
|
28
|
+
program_run check: !!check, args: args
|
29
|
+
end
|
30
|
+
|
31
|
+
When /^I( successfully)? run the program with options? (-.+)$/ do |check, opts|
|
32
|
+
program_run check: !!check, opts: opts
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
Then /^the exit status must be (\d+)$/ do |exit_status|
|
37
|
+
program_run_check status: exit_status.to_i
|
38
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
def build_regexp pattern, options
|
2
|
+
Regexp.new(pattern, options.each_char.inject(0) do |m, e|
|
3
|
+
m | case e
|
4
|
+
when ?i then Regexp::IGNORECASE
|
5
|
+
when ?m then Regexp::MULTILINE
|
6
|
+
when ?x then Regexp::EXTENDED
|
7
|
+
end
|
8
|
+
end)
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
Then /^the output must contain exactly:$/ do |content|
|
13
|
+
expect(last_command_started.output).to eq unescape_text content + $/
|
14
|
+
end
|
15
|
+
|
16
|
+
Then /^the output must contain exactly "([^"]+)"$/ do |content|
|
17
|
+
expect(last_command_started.output).to eq unescape_text content
|
18
|
+
end
|
19
|
+
|
20
|
+
Then /^the output must match \/([^\/]+)\/([a-z]*)$/ do |pattern, options|
|
21
|
+
expect(last_command_started.output).to match build_regexp(pattern, options)
|
22
|
+
end
|
data/lib/baf/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: baf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thibault Jouan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aruba
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.11'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0.12'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.11'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.12'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: cucumber
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.4'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.4'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.4'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.4'
|
75
|
+
description: Basic Application Framework
|
76
|
+
email: tj@a13.fr
|
77
|
+
executables: []
|
78
|
+
extensions: []
|
79
|
+
extra_rdoc_files: []
|
80
|
+
files:
|
81
|
+
- lib/baf.rb
|
82
|
+
- lib/baf/cli.rb
|
83
|
+
- lib/baf/env.rb
|
84
|
+
- lib/baf/option_registrant.rb
|
85
|
+
- lib/baf/testing/cucumber.rb
|
86
|
+
- lib/baf/testing/cucumber/steps/execution.rb
|
87
|
+
- lib/baf/testing/cucumber/steps/output.rb
|
88
|
+
- lib/baf/version.rb
|
89
|
+
homepage: https://rubygems.org/gems/baf
|
90
|
+
licenses:
|
91
|
+
- BSD-3-Clause
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.5.1
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Basic Application Framework
|
113
|
+
test_files: []
|
114
|
+
has_rdoc:
|