module
Athena::Spec::Methods
Overview
Namespace for common/helpful testing methods.
This module can be included into your spec_helper in order
to allow your specs to use them all. This module is also
included into ASPEC::TestCase by default to allow using them
within your unit tests as well.
May be reopened to add additional application specific helpers.
Extended Modules
Direct including types
Defined in:
methods.crInstance Method Summary
-
#assert_compile_time_error(message : String, code : String, *, line : Int32 = __LINE__, file : String = __FILE__) : Nil
Executes the provided Crystal code and asserts it results in a compile time error with the provided message.
-
#assert_compiles(code : String, *, line : Int32 = __LINE__, file : String = __FILE__) : Nil
Similar to
.assert_compile_time_error, but asserts the provided Crystal code successfully compiles. -
#assert_executes(code : String, *, line : Int32 = __LINE__, file : String = __FILE__) : Nil
Similar to
.assert_runtime_error, but asserts the provided Crystal code successfully executes. -
#assert_runtime_error(message : String, code : String, *, line : Int32 = __LINE__, file : String = __FILE__) : Nil
Executes the provided Crystal code and asserts it results in a runtime error with the provided message.
-
#run_executable(path : String, args : Array(String) = [] of String, & : String, String, Process::Status -> ) : Nil
Runs the executable at the given path, optionally with the provided args.
-
#run_executable(path : String, input : IO, args : Array(String) = [] of String, & : String, String, Process::Status -> ) : Nil
Runs the executable at the given path, with the given input, optionally with the provided args.
Instance Method Detail
Executes the provided Crystal code and asserts it results in a compile time error with the provided message.
ASPEC::Methods.assert_compile_time_error "can't instantiate abstract class Foo", <<-CR
abstract class Foo; end
Foo.new
CR
NOTE When files are required within the code, they are relative to the file calling this method.
Similar to .assert_compile_time_error, but asserts the provided Crystal code successfully compiles.
ASPEC::Methods.assert_compiles <<-CR
raise "Still passes"
CR
NOTE When files are required within the code, they are relative to the file calling this method.
Similar to .assert_runtime_error, but asserts the provided Crystal code successfully executes.
ASPEC::Methods.assert_executes <<-CR
puts 2 + 2
CR
NOTE When files are required within the code, they are relative to the file calling this method.
Executes the provided Crystal code and asserts it results in a runtime error with the provided message. This can be helpful in order to test something in isolation, without affecting other test cases.
ASPEC::Methods.assert_runtime_error "Oh noes!", <<-CR
raise "Oh noes!"
CR
NOTE When files are required within the code, they are relative to the file calling this method.
Runs the executable at the given path, optionally with the provided args.
The standard output, error output, and status of the execution are yielded.
require "athena-spec"
ASPEC::Methods.run_executable "/usr/bin/ls" do |output, error, status|
output # => "docs\n" + "LICENSE\n" + "README.md\n" + "shard.yml\n" + "spec\n" + "src\n"
error # => ""
status # => #<Process::Status:0x7f7bc9befb70 @exit_status=0>
end
Runs the executable at the given path, with the given input, optionally with the provided args.
The standard output, error output, and status of the execution are yielded.
require "athena-spec"
input = IO::Memory.new %({"id":1})
ASPEC::Methods.run_executable "jq", input, [".", "-c"] do |output, error, status|
output # => "{\"id\":1}\n"
error # => ""
status # => #<Process::Status:0x7f26ec698b70 @exit_status=0>
end
invalid_input = IO::Memory.new %({"id"1})
ASPEC::Methods.run_executable "jq", invalid_input, [".", "-c"] do |output, error, status|
output # => ""
error # => "parse error: Expected separator between values at line 1, column 7\n"
status # => #<Process::Status:0x7f0217496900 @exit_status=1024>
end