diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e9f41fa..fd81d0c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,3 +15,16 @@ spec: script: - crystal tool format --check - crystal spec + +pages: + stage: deploy + dependencies: + - spec + script: + - crystal docs + - mv docs/ public/ + artifacts: + paths: + - public + only: + - master diff --git a/README.md b/README.md index 59846b1..32f7304 100644 --- a/README.md +++ b/README.md @@ -347,6 +347,9 @@ Macros that create types are not as easy to test, so they are exempt for the current time. However, please test all code locally with an example spec file. +Documentation is automatically generated and published to GitLab pages. +It can be found here: https://arctic-fox.gitlab.io/spectator + Contributors ------------ diff --git a/src/spectator.cr b/src/spectator.cr index fa87ede..b11eef7 100644 --- a/src/spectator.cr +++ b/src/spectator.cr @@ -5,7 +5,7 @@ module Spectator extend self # Current version of the Spectator library. - VERSION = "0.1.0" + VERSION = "0.5.0" # Top-level describe method. # All specs in a file must be wrapped in this call. diff --git a/src/spectator/dsl/matcher_dsl.cr b/src/spectator/dsl/matcher_dsl.cr index 8311005..ac4315d 100644 --- a/src/spectator/dsl/matcher_dsl.cr +++ b/src/spectator/dsl/matcher_dsl.cr @@ -527,7 +527,7 @@ module Spectator::DSL # expect_raises { raise "foobar" } # ``` macro expect_raises - expect {{yield}}.to raise_error + expect {{block}}.to raise_error end # Indicates that some block should raise an error with a given type. diff --git a/src/spectator/dsl/structure_dsl.cr b/src/spectator/dsl/structure_dsl.cr index 2cceea4..93dfe94 100644 --- a/src/spectator/dsl/structure_dsl.cr +++ b/src/spectator/dsl/structure_dsl.cr @@ -1412,6 +1412,34 @@ module Spectator::DSL ::Spectator::DSL::Builder.add_example(Example%example) end + # Creates an example, or a test case. + # The block contains the code to run the test. + # One or more expectations should be in the block. + # + # ``` + # it { expect(1 + 2).to eq(3) } + # ``` + # + # See `ExampleDSL` and `MatcherDSL` for additional macros and methods + # that can be used in example code blocks. + # + # A short-hand, one-liner syntax can also be used. + # Typically, this is combined with `#subject`. + # For instance: + # ``` + # subject { 1 + 2 } + # it is_expected.to eq(3) + # ``` + macro it(&block) + it({{block.body.stringify}}) {{block}} + end + + # An alternative way to write an example. + # This is identical to `#it`. + macro specify(what, &block) + it({{what}}) {{block}} + end + # An alternative way to write an example. # This is identical to `#it`, # except that it doesn't take a "what" argument. @@ -1456,12 +1484,33 @@ module Spectator::DSL ::Spectator::DSL::Builder.add_example(Example%example) end + # Creates an example, or a test case, that does not run. + # This can be used to prototype functionality that isn't ready. + # The *what* argument describes "what" is being tested or asserted. + # The block contains the code to run the test. + # One or more expectations should be in the block. + # + # ``` + # pending do + # # Something that isn't implemented yet. + # end + # ``` + macro pending(&block) + peding({{block.body.stringify}}) {{block}} + end + # Same as `#pending`. # Included for compatibility with RSpec. macro xit(what, &block) pending({{what}}) {{block}} end + # Same as `#pending`. + # Included for compatibility with RSpec. + macro xit(&block) + pending({{block.body.stringify}}) {{block}} + end + # Creates a wrapper class for test code. # The class serves multiple purposes, mostly dealing with scope. # 1. Include the parent modules as mix-ins.