SexySpex.DSL (sexy_spex v0.1.0)

View Source

Domain-specific language for writing executable specifications.

Provides macros for structuring specifications in a readable, executable format following the Given-When-Then pattern.

Summary

Functions

Defines additional context or cleanup.

Defines the preconditions for a test scenario.

Defines a scenario within a specification.

Defines a scenario with context support.

Defines a specification.

Defines the expected outcome.

Defines the action being tested.

Functions

and_(description, list)

(macro)

Defines additional context or cleanup.

and_(description, context_var, list)

(macro)

given_(description, list)

(macro)

Defines the preconditions for a test scenario.

Examples

# Without context
given_ "some setup" do
  # setup code
end

# With context (ExUnit style)
given_ "some setup", context do
  data = setup()
  context = Map.put(context, :data, data)
end

given_(description, context_var, list)

(macro)

scenario(name, list)

(macro)

Defines a scenario within a specification.

Scenarios group related Given-When-Then steps together.

scenario(name, context_var, list)

(macro)

Defines a scenario with context support.

Context is passed between steps similar to ExUnit's approach.

Example

scenario "user workflow", context do
  given_ "a user", context do
    user = create_user()
    context = Map.put(context, :user, user)
  end

  when_ "they login", context do
    session = login(context.user)
    context = Map.put(context, :session, session)
  end

  then_ "they see dashboard", context do
    assert context.session.valid?
  end
end

spex(name, opts \\ [], list)

(macro)

Defines a specification.

Example

spex "user can login", tags: [:authentication] do
  scenario "with valid credentials" do
    # test implementation
  end
end

Options

  • :description - Human-readable description of the specification
  • :tags - List of atoms for categorizing the specification
  • :context - Map of additional context information

then_(description, list)

(macro)

Defines the expected outcome.

then_(description, context_var, list)

(macro)

when_(description, list)

(macro)

Defines the action being tested.

when_(description, context_var, list)

(macro)