Top Level Namespace
Defined Under Namespace
Modules: Exemplor Classes: String
Instance Method Summary collapse
-
#eg(name = nil, &example) ⇒ Object
Interface for defining examples and configuring their environment.
-
#Exemplor(args) ⇒ Object
takes an array of command line arguments.
- #OrderedHash(&blk) ⇒ Object
Instance Method Details
#eg(name = nil, &example) ⇒ Object
Interface for defining examples and configuring their environment.
To define an example call eg with a name and block
eg "yellling" do
"hi".capitalize
end
‘eg` can be called without a name if the entire call is on one line, in that case the code in the example is used as its name:
eg { the_duck_swims_in_the_pond }
same as:
eg("the_duck_swims_in_the_pond") { the_duck_swims_in_the_pond }
Call ‘eg` without args to configure the examples enviornment:
eg.setup do
# code here will run before each example
end
eg.helpers do
# methods defined here can be called from inside an example
end
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/exemplor.rb', line 55 def eg(name = nil, &example) called_without_args = name.nil? && example.nil? return Exemplor.environment if called_without_args Exemplor.set_example_file_from caller unless Exemplor.example_file_set? called_without_explicit_name = name.nil? && !example.nil? name = Exemplor.make_example_name_from caller if called_without_explicit_name Exemplor.examples.add(name, &example) end |
#Exemplor(args) ⇒ Object
takes an array of command line arguments
2 3 4 5 6 7 8 9 |
# File 'lib/command.rb', line 2 def Exemplor(args) args = args.dup if args.delete('--list') || args.delete('-l') Exemplor.examples.list(args) else exit Exemplor.examples.run(args) end end |
#OrderedHash(&blk) ⇒ Object
1 2 3 4 5 |
# File 'lib/ext.rb', line 1 def OrderedHash(&blk) ohsh = OrderedHash.new blk.call(ohsh) ohsh end |