tryouts 0.8.8 → 2.0.0

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.
@@ -1,176 +0,0 @@
1
-
2
- class Tryouts
3
-
4
- # = Tryout
5
- #
6
- # A Tryout is a set of drills (each drill is a test).
7
- #
8
- class Tryout
9
-
10
- # The name of this tryout
11
- attr_reader :name
12
- # A default value for Drill.dtype
13
- attr_reader :dtype
14
- # A block to executed one time before starting the drills
15
- attr_reader :setup
16
- # A block to executed one time before starting the drills
17
- attr_reader :clean
18
- # An Array of Drill objects
19
- attr_reader :drills
20
- # The number of dreams that came true (successful drills)
21
- attr_reader :passed
22
- # The number of dreams that did not come true (failed drills)
23
- attr_reader :failed
24
- # The number of skipped drills
25
- attr_reader :skipped
26
- # For drill type :cli, this is the name of the command to test. It
27
- # should be a valid method available to a Rye::Box object.
28
- # For drill type :api, this attribute is ignored.
29
- attr_reader :command
30
- # A Hash of Dream objects for this Tryout. The keys are drill names.
31
- attr_reader :dream_catcher
32
-
33
- # The instance of Drill::Context in which the drills will run in.
34
- attr_reader :drill_context
35
-
36
- def initialize(name, dtype, command=nil, *args)
37
- raise "Must supply command for dtype :cli" if dtype == :cli && command.nil?
38
- raise "#{dtype} is not a valid drill type" if !Drill.valid_dtype?(dtype)
39
- @name, @dtype, @command = name, dtype, command
40
- @drills, @dream_catcher, @locals = [], [], {}
41
- @passed, @failed, @skipped = 0, 0, 0
42
- @drill_context = DrillContext.new
43
- end
44
-
45
- ## --------------------------------------- EXTERNAL API -----
46
-
47
- # Populate this Tryout from a block. The block should contain calls to
48
- # the external DSL methods: dream, drill, xdrill
49
- def from_block(b=nil, &inline)
50
- runtime = b.nil? ? inline : b
51
- begin
52
- instance_eval &runtime
53
- rescue => ex
54
- raise ex
55
- end
56
- end
57
-
58
- # Execute all Drill objects
59
- def run
60
- @drill_context.instance_eval &setup if setup.is_a?(Proc)
61
- puts "\n %s ".bright % @name unless Tryouts.verbose < 0
62
- @drills.each do |drill|
63
- print ' %-69s ' % "\"#{drill.name}\"" unless Tryouts.verbose < 0
64
- drill.run @drill_context
65
- if drill.skip?
66
- @skipped += 1
67
- elsif drill.success?
68
- @passed += 1
69
- else
70
- @failed += 1
71
- end
72
- puts drill.flag # PASS, FAIL, SKIP
73
- puts drill.info if Tryouts.verbose > 0 && !drill.skip?
74
- end
75
- @drill_context.instance_eval &clean if clean.is_a?(Proc)
76
- end
77
-
78
- # Prints error output. If there are no errors, it prints nothing.
79
- def report
80
- return if Tryouts.verbose < 0
81
- failed = @drills.select { |d| !d.skip? && !d.success? }
82
- failed.each_with_index do |drill,index|
83
- title = ' %-69s %2d/%-2d ' % ["\"#{drill.name}\"", index+1, failed.size]
84
- puts $/, ' ' << title.color(:red).att(:reverse)
85
- puts drill.report
86
- end
87
- if Tryouts.verbose > 0
88
- # Print errors for successful runs too
89
- success = @drills.select { |d| !d.skip? && d.success? }
90
- success.each do |drill,index|
91
- next unless drill.has_error?
92
- title = ' Non-fatal error in: %-69s ' % ["\"#{drill.name}\""]
93
- puts $/, ' ' << title.color(:red)
94
- puts drill.report
95
- end
96
- end
97
- end
98
-
99
- # Did every Tryout finish successfully?
100
- def success?
101
- return @success unless @success.nil?
102
- # Returns true only when every Tryout result returns true
103
- @success = !(@drills.collect { |r| r.success? }.member?(false))
104
- end
105
-
106
- # Add a Drill object to the list for this Tryout. If there is one or
107
- # more dreams in +@dream_catcher+, it will be added to drill +d+.
108
- def add_drill(d)
109
- unless @dream_catcher.empty?
110
- d.add_dreams *@dream_catcher.clone # We need to clone here b/c
111
- @dream_catcher.clear # Ruby passes by reference.
112
- end
113
- drills << d
114
- d
115
- end
116
-
117
- ## ------------------------------------------------ DSL -----
118
-
119
- # Define a method named +key+ for only the current instances of
120
- # Tryout and DrillContext so it's not available anywhere else.
121
- # The methods return +value+.
122
- def set(key, value)
123
- self.meta_def( key ) { value }
124
- @drill_context.meta_def( key ) { value }
125
- value
126
- end
127
-
128
- # A block to executed one time _before_ starting the drills
129
- def setup(&block)
130
- return @setup unless block
131
- @setup = block
132
- end
133
-
134
- # A block to executed one time _after_ the drills
135
- def clean(&block)
136
- return @clean unless block
137
- @clean = block
138
- end
139
-
140
- # Create and add a Drill object to the list for this Tryout
141
- # +name+ is the name of the drill.
142
- # +args+ is sent directly to the Drill class. The values are specific on the Sergeant.
143
- def drill(dname, *args, &definition)
144
- raise "Empty drill name (#{@name})" if dname.nil? || dname.empty?
145
- # The command name to run should be the first argument
146
- args.unshift @command if @dtype == :cli
147
- drill = Tryouts::Drill.new(dname, @dtype, *args, &definition)
148
- self.add_drill drill
149
- end
150
- # A quick way to comment out a drill
151
- def xdrill(dname, *args, &b)
152
- @dream_catcher.clear # Otherwise the next drill will get them...
153
- self.add_drill Tryouts::Drill.new(dname, :skip)
154
- end
155
-
156
-
157
- #
158
- # NOTE: This method is DSL-only. It's not intended to be used in OO syntax.
159
- def dream(*args, &definition)
160
- if definition.nil?
161
- args = args.size == 1 ? [args.first] : args.reverse
162
- dobj = Tryouts::Drill::Dream.new(*args)
163
- else
164
- msg = "Dreams with blocks take only 1 argument (Tryout: '#{@name}')"
165
- raise TooManyArgs, msg if args.size > 1
166
- dobj = Tryouts::Drill::Dream.new
167
- dobj.format = args.first if args.size == 1
168
- dobj.output_block = definition
169
- end
170
- @dream_catcher.push dobj
171
- dobj
172
- end
173
- # A quick way to comment out a dream
174
- def xdream(*args, &b); end
175
-
176
- end; end
@@ -1,23 +0,0 @@
1
- library :tryouts, 'lib'
2
-
3
- group "Mixins"
4
-
5
- test_hash = {
6
- :level1 => {
7
- :level2 => {},
8
- :apples => 1
9
- },
10
- :help => [1, :a, 900001, Object.new, Hash],
11
- :oranges => 90
12
- }
13
-
14
-
15
- tryouts "Hash", :api do
16
- setup do
17
-
18
- end
19
-
20
- drill "knows the deepest point", test_hash.deepest_point, 3
21
- drill "has a last method", {}, :respond_to?, :last
22
-
23
- end
@@ -1,44 +0,0 @@
1
-
2
- tryout "DSL Syntax", :api do
3
-
4
- drill "can specify a dream inline", 3 do
5
- 12 / 4
6
- end
7
-
8
- dream 4770744
9
- drill "can specify dream above the drill" do
10
- 4770744
11
- end
12
-
13
- dream :class, Array
14
- drill "can pass based on output object class" do
15
- [1,2,3]
16
- end
17
-
18
- dream :exception, NameError
19
- drill "can pass based on exception class" do
20
- bad_method_call
21
- end
22
-
23
- drill "dreamless drills that return true will pass" do
24
- true
25
- end
26
-
27
- drill "inline true values will pass too", true
28
- drill "can specify inline return values", :food, :food
29
- drill "can specify match format", 'mahir', :match, /..hi./i
30
-
31
- dream "big"
32
- dream :class, String
33
- dream :match, /\Ab.g\z/
34
- drill "can handle multiple dreams" do
35
- "big"
36
- end
37
-
38
- drill "can specify gt (>) format", 2, :gt, 1
39
- drill "can specify gte (>=) format", 2, :gte, 2
40
- drill "can specify lt (<) format", 1, :lt, 2
41
- drill "can specify lte (<=) format", 2, :lte, 2
42
-
43
- drill "can run arbitrary formats", [3,1,2], :sort, [1,2,3]
44
- end
@@ -1,26 +0,0 @@
1
- library :tryouts, 'lib'
2
- group "Syntax"
3
-
4
- tryouts "Set (initial)" do
5
- set :key1, 9000
6
- drill "set values are available outside drill/dream blocks", key1 do
7
- 9000
8
- end
9
- drill "set values are available inside drill/dream blocks", 9000 do
10
- key1
11
- end
12
- end
13
-
14
- tryouts "Set (double check)" do
15
-
16
- dream :exception, NameError
17
- drill "set values are not available from other tryouts inside blocks" do
18
- key1
19
- end
20
-
21
- ## NOTE: This drill will create a runtime error b/c key1 isn't defined here.
22
- ## dream key1
23
- ## drill "set values are not available from other tryouts outside blocks" do
24
- ## end
25
-
26
- end
@@ -1,54 +0,0 @@
1
- library :tryouts, 'lib'
2
- group "Syntax"
3
-
4
- tryouts "Dreams" do
5
-
6
- setup do
7
- Tryouts.const_set :TEST_VALUE, 9000
8
- end
9
-
10
- drill "dream inline", :muggsy do
11
- :muggsy
12
- end
13
-
14
- dream :muggsy
15
- drill "dream on top" do
16
- :muggsy
17
- end
18
-
19
- dream do
20
- :muggsy
21
- end
22
- drill "dream output can be specified with a block" do
23
- :muggsy
24
- end
25
-
26
- dream :class do
27
- Symbol
28
- end
29
- drill "dream with a format argument and a block" do
30
- :muggsy
31
- end
32
-
33
- # NOTE: The constant is defined in the setup block which is called before the
34
- # drill block is executed. As of 0.8.2 the dream block is executed literally
35
- # just before the drill block which is why this test returns true.
36
- dream do
37
- Tryouts.const_get :TEST_VALUE
38
- end
39
- drill "dream output from a block is executed just before the drill" do
40
- 9000
41
- end
42
-
43
- ## NOTE: The following should raise a Tryouts::TooManyArgs error b/c dreams takes 1 arg
44
- #
45
- #dream :class, 2 do
46
- # Symbol
47
- #end
48
- #drill "dream with a format argument and a block" do
49
- # :muggsy
50
- #end
51
- #
52
- #drill "this drill will fail b/c it has no dream", :muggsy
53
-
54
- end
@@ -1,40 +0,0 @@
1
-
2
- TRYOUTS_HOME = File.expand_path(File.join(File.dirname(__FILE__), ".."))
3
- MOCKOUT_PATH = File.join(TRYOUTS_HOME, "bin", "mockout")
4
-
5
- group "CLI"
6
- command :mockout, MOCKOUT_PATH
7
-
8
- tryout "Mockouts", :cli do
9
-
10
- # This fails. Rye problem?
11
- dream :class, Rye::Rap
12
- dream []
13
- drill "No args"
14
-
15
- dream ["One line of content"]
16
- drill "can echo single argument", :echo, "One line of content"
17
-
18
- dream ["Two lines", "of content"]
19
- drill "can echo single argument with line break", :echo, "Two lines#{$/}of content"
20
-
21
- dream :grep, /UTC/
22
- drill "can display date", :date
23
-
24
- dream []
25
- drill "can be quiet", :q, :test
26
-
27
- dream ["PASS"]
28
- drill "can execute via a block" do
29
- mockout :test, :p
30
- end
31
-
32
- dream :match, /\d+\.\d+\.\d+\.\d+/
33
- drill "can execute a block of commands" do
34
- ret = rudy :q, :myaddress, :e
35
- ret.first
36
- end
37
-
38
- end
39
-
40
-
@@ -1,27 +0,0 @@
1
-
2
-
3
- group "Benchmarks"
4
-
5
- tryouts "Benchmark Syntax", :benchmark do
6
-
7
- drill "can check the mean is <=" do
8
- sleep 0.1
9
- end
10
-
11
- drill "can check the standard deviation" do
12
- sleep 0.1
13
- end
14
-
15
- drill "Tryouts::Stat objects have a default name" do
16
- sleep 0.1
17
- end
18
-
19
- drill "default repetitions is 5" do
20
- sleep 0.1
21
- end
22
-
23
- dream :proc, lambda { |x| x[:real].sum >= 0.5 }
24
- drill "can specify dream proc" do
25
- sleep 0.1
26
- end
27
- end
@@ -1,33 +0,0 @@
1
-
2
- group "Class context tests"
3
-
4
- tryout "Setting class variables", :api do
5
- setup do
6
- class ::Olivia; end
7
- @@from_setup = Olivia.new # NOTE: module_eval seems to solve this problem
8
- @from_setup = true
9
- end
10
-
11
- if Tryouts.sysinfo.ruby[1] == 9
12
- drill "can't access class var created in setup (1.9 only)", :exception, NameError do
13
- @@from_setup
14
- end
15
- end
16
-
17
- if Tryouts.sysinfo.ruby[1] == 8
18
- drill "can access class var created in setup (1.8 only)", 'Olivia' do
19
- @@from_setup.class.to_s
20
- end
21
- end
22
-
23
- drill "create class var", 'Olivia' do
24
- @@from_drill = Olivia.new
25
- @@from_drill.class.to_s
26
- end
27
-
28
- drill "can access class var created in drill", 'Olivia' do
29
- @@from_drill.class.to_s
30
- end
31
-
32
- drill 'Small, fast, and furious', 'Muggsy Bogues', :match, /Mug+sy Bogu?es/
33
- end
@@ -1,78 +0,0 @@
1
- ## Tryouts 0.8
2
-
3
- library :rudy, 'path/2/rudy/lib'
4
- tryouts "Code", :api do
5
-
6
- setup do
7
- end
8
-
9
-
10
- dream :class, Rudy::Disk
11
- dream :size, 1
12
- dream :device, '/dev/sdh'
13
- dream :path, '/'
14
- drill "has a default size and device" do
15
- Rudy::Disk.new('/')
16
- end
17
-
18
- drill "save disk metadata", true do
19
- Rudy::Disk.new('/any/path').save
20
- end
21
-
22
- dream :exception, Rudy::Metadata::DuplicateRecord
23
- drill "won't save over a disk with the same name" do
24
- Rudy::Disk.new('/any/path').save
25
- end
26
-
27
- set :group_name, "grp-9000"
28
- dream :class, Rudy::AWS::EC2::Group
29
- dream :proc, lambda { |group|
30
- accountnum = Rudy::Huxtable.config.accounts.aws.accountnum
31
- should_have = "#{accountnum}:#{group_name}"
32
- return false unless group.groups.is_a?(Hash)
33
- group.groups.has_key?(should_have) == true
34
- }
35
- drill "group (#{group_name}) contains new rules" do
36
- stash :group, Rudy::AWS::EC2::Groups.get(group_name)
37
- end
38
- end
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
- # "has a default size and device"
48
- Rudy::Disk.new '/' # <Rudy::Disk>
49
- #=> # obj.size == 1
50
- # obj.device == '/dev/sdh'
51
- # obj.path == '/'
52
-
53
- # "save disk metadata"
54
- Rudy::Disk.new('/any/path').save # true
55
-
56
- # "won't save over a disk with the same name"
57
- Rudy::Disk.new('/any/path').save # ! <Rudy::Metadata::DuplicateRecord>
58
-
59
- # "group contains new rules"
60
- group_name = "grp-9000"
61
- accountnum = Rudy::Huxtable.config.accounts.aws.accountnum
62
- obj = Rudy::AWS::EC2::Groups.get(group_name)
63
- obj.class #=> Rudy::AWS::EC2::Group
64
- obj.groups.has_key?("#{accountnum}:#{group_name}") #=> true
65
- obj.device #=> '/dev/sdh'
66
-
67
- ### Context b ###
68
-
69
- obj.path #=> '/'
70
-
71
-
72
- Foo::bar() #=> "asdf"
73
-
74
- result = Foo::bar()
75
- result #=> "asdf"
76
-
77
- # work with:
78
- # $ ruby -rubygems -Ilib ...
@@ -1,36 +0,0 @@
1
- ## Tryouts 0.8
2
-
3
- command :script, '/path/2/script'
4
-
5
- tryouts "CLI", :cli do
6
- dream :grep, /UTC/
7
- drill "can display date", :date
8
-
9
- dream []
10
- drill "can be quiet", :q, :test
11
-
12
- dream :match, /\d+\.\d+\.\d+\.\d+/
13
- drill "can execute a block of commands" do
14
- ret = rudy :q, :myaddress, :e
15
- ret.first
16
- end
17
- end
18
-
19
- ## Comment-style
20
-
21
- command :script, '/path/2/script'
22
- tryouts "CLI", :cli do
23
-
24
- # "can display date"
25
- script :date # stdout.grep /UTC/
26
- # stderr.empty? == true
27
-
28
- # "can be quiet"
29
- script :q, :test # stdout.empty? == true
30
-
31
- # "can execute a block of commands"
32
- ls :a, '/tmp'
33
- script :q, :myaddress, :e # stdout.first.match /\d+\.\d+\.\d+\.\d+/
34
-
35
- end
36
-
@@ -1,39 +0,0 @@
1
- ## Tryouts - Standalone Test
2
- #
3
- # This tryout is intended to be run on its own,
4
- # without the tryouts exectuable. That's why it's
5
- # named _test.rb, so tryouts won't see it. It uses
6
- # the same dreams as MockoutCLI.
7
- #
8
- # Usage: ruby tryouts/standalone_test.rb
9
- #
10
-
11
- ## NOTE: BROKEN SINCE 0.6
12
-
13
- TRYOUTS_HOME = File.expand_path(File.join(File.dirname(__FILE__), '..'))
14
- TRYOUTS_LIB = File.join(TRYOUTS_HOME, 'lib')
15
- MOCKOUT_PATH = File.join(TRYOUTS_HOME, 'bin', 'mockout')
16
- $:.unshift TRYOUTS_LIB # Put our local lib in first place
17
-
18
- require 'tryouts'
19
-
20
- class StandaloneCLI < Tryouts
21
- command :mockout, MOCKOUT_PATH
22
- #dreams File.join(TRYOUTS_HOME, 'tryouts', 'mockoutcli_dreams.rb')
23
-
24
- tryout "common usage" do
25
- drill 'no command'
26
- drill 'no args', :sergeant
27
- drill 'yaml output', :f, 'yaml', :sergeant
28
- drill 'json output', :f, 'json', :sergeant
29
- end
30
-
31
- tryout "inline dream will pass", :cli, :mockout do
32
- output = ['we expect mockout to', 'echo these lines back']
33
- dream output
34
- # $ bin/mockout sergeant -e 'we expect mockout to' 'echo these lines back'
35
- drill 'echo arguments', :sergeant, :e, *output
36
- end
37
- end
38
-
39
- StandaloneCLI.run
data/tryouts.gemspec DELETED
@@ -1,84 +0,0 @@
1
- @spec = Gem::Specification.new do |s|
2
- s.name = "tryouts"
3
- s.rubyforge_project = "tryouts"
4
- s.version = "0.8.8"
5
- s.summary = "Tryouts is a high-level testing library (DSL) for your Ruby codes and command-line applications."
6
- s.description = s.summary
7
- s.author = "Delano Mandelbaum"
8
- s.email = "tryouts@solutious.com"
9
- s.homepage = "http://github.com/delano/tryouts"
10
-
11
- # = EXECUTABLES =
12
- # The list of executables in your project (if any). Don't include the path,
13
- # just the base filename.
14
- s.executables = %w[sergeant]
15
-
16
- # Directories to extract rdocs from
17
- s.require_paths = %w[lib]
18
-
19
- # Specific files to include rdocs from
20
- s.extra_rdoc_files = %w[README.rdoc LICENSE.txt CHANGES.txt]
21
-
22
- # Update --main to reflect the default page to display
23
- s.rdoc_options = ["--line-numbers", "--title", "Tryouts: #{s.summary}", "--main", "README.rdoc"]
24
-
25
- ## NOTE: this is for Rudy conversion (incomplete)
26
- ##rdoc '--line-numbers', '--title', "Tryouts: Basketball tryouts for your Ruby codes and command line apps. Go for it!", '--main', 'README.rdoc',
27
-
28
- # = DEPENDENCIES =
29
- # Add all gem dependencies
30
- s.add_dependency 'rye'
31
- s.add_dependency 'drydock'
32
- s.add_dependency 'sysinfo'
33
-
34
- # = MANIFEST =
35
- # The complete list of files to be included in the release. When GitHub packages your gem,
36
- # it doesn't allow you to run any command that accesses the filesystem. You will get an
37
- # error. You can ask your VCS for the list of versioned files:
38
- # git ls-files
39
- # svn list -R
40
- s.files = %w(
41
- CHANGES.txt
42
- LICENSE.txt
43
- README.rdoc
44
- Rakefile
45
- bin/mockout
46
- bin/sergeant
47
- lib/tryouts.rb
48
- lib/tryouts/cli.rb
49
- lib/tryouts/cli/run.rb
50
- lib/tryouts/drill.rb
51
- lib/tryouts/drill/context.rb
52
- lib/tryouts/drill/dream.rb
53
- lib/tryouts/drill/reality.rb
54
- lib/tryouts/drill/response.rb
55
- lib/tryouts/drill/sergeant/api.rb
56
- lib/tryouts/drill/sergeant/benchmark.rb
57
- lib/tryouts/drill/sergeant/cli.rb
58
- lib/tryouts/drill/sergeant/rbenchmark.rb
59
- lib/tryouts/mixins.rb
60
- lib/tryouts/orderedhash.rb
61
- lib/tryouts/stats.rb
62
- lib/tryouts/tryout.rb
63
- tryouts.gemspec
64
- tryouts/01_mixins_tryouts.rb
65
- tryouts/10_syntax_tryouts.rb
66
- tryouts/14_set_tryouts.rb
67
- tryouts/15_dreams_tryouts.rb
68
- tryouts/20_cli_tryouts.rb
69
- tryouts/30_benchmark_tryouts.rb
70
- tryouts/50_class_context_tryouts.rb
71
- tryouts/X1_new_api_syntax.rb
72
- tryouts/X2_new_cli_syntax.rb
73
- tryouts/standalone_test.rb
74
- )
75
-
76
- s.has_rdoc = true
77
- s.rubygems_version = '1.3.0'
78
-
79
- if s.respond_to? :specification_version then
80
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
81
- s.specification_version = 2
82
- end
83
-
84
- end