没有任何数据可供显示
开源项目社区 | 当前位置 : |
|
oss.trustie.net/open_source_projects | 主页 > 开源项目社区 > tryouts |
tryouts
|
0 | 0 | 0 |
贡献者 | 讨论 | 代码提交 |
Tryouts - v0.8 BETATryouts is a high-level testing library (DSL) for your Ruby codes and command-line applications.
A tryout is made up of one of more drills. The return value of the drill block is compared to the expectations defined by one or more dreams. The goal is to achieve your dreams.
TerminologyTryout: a set of drills (think: basketball tryouts) Drill: a single test. Drill Sergeant: The class responsible for executing a drill. Dream: the expected outcome of a drill. There's always one or more dream per drill. Installation $ gem install tryoutsWriting TestsThe examples below are a complete overview of Tryouts syntax.
Testing Ruby Codes (:api) library :gibbler, "../path/to/gibbler/lib"
tryouts "Common Usage", :api do
- Define variables available only within
# in the current tryout definition.
set :local_variable, 3
setup do
# do stuff before all drills
end
clean do
# do stuff after all drills
end
- This drill block should return 3.
drill "Maths R Us", local_variable do
12 / 4
end
- You can specify a method to execute
- on the return value of the drill block.
drill "We want a symbol", :class, Symbol do
Class.methods.first
end
- Dreams can also be specified explicitly which is
- important b/c it's possible to specify multiple.
dream :class, Array
dream ['b', 'c', 'd']
drill "Should return a list of 3" do
letters = 'a'..'z'
letters.to_a[1..local_variable]
end
- Drills can pass based on an exception too.
dream :exception, NameError
drill "Something failed" do
raise NameError
end
- We can even put simple drills on a single line.
drill 'Small, fast, and furious', 'Muggsy Bogues', :match, /Mug+sy Bogu?es/
endTesting Command-Line Applications (:cli)You can execute drills on command-line applications.
command :rudy, "path/2/rudy"
tryouts "Rudy CLI", :cli do
- We have specified the name of the command above so
- we only need to specify the arguments in the drill.
- $ rudy myaddress -e
drill "can display my IP addresses", :myaddress, :e
- The drill returns an Array of lines from STDOUT so
- we can use Array#grep to check the command output.
- If any lines match, this test will pass.
dream :grep, /No machines running/
drill "can call with no arguments"
- Drills can also be defined with a block which gets
- executed via Rye::Box#batch. Methods in the block
- are executed as commands. The return value of the
- block is considered the test output.
dream :match, /\d+\.\d+\.\d+\.\d+/
drill "can execute a block of commands" do
ret = rudy :q, :myaddress, :e
ret.first
end
endRunning Performance Benchmarks (:benchmark)You can also use Tryouts to run benchmarks. The tryouts method takes a second parameter which specifies which drill sergeant to use. Below we specify :benchmark so each drill is timed and executed multiple times.
tryouts "Benchmark examples", :benchmark do
- We create an Array and store it in a class
- variable so it's available to other drills.
drill "Create test array" do
@@array = (1..100000).map { rand }
end
dream :mean, 3.0 # The mean should be means that this library is not thread-safe at definition-time. However, once all tryouts files are parsed (or in OO-syntax, once all objects are created), this class should be thread-safe at drill-time.
More InfoCheck out the sourcecodes Read the rdocs Inspiration ThanksEveryone at Utrecht.rb and Amsterdam.rb for putting up with my Ruby questions :] Sam Aaron (http://sam.aaron.name) for the early feedback. Kalin Harvey for the encouragement. Credits Delano (@solutious.com)
Related ProjectsContext Testy Expectations Zebra LicenseSee: LICENSE.txt