Skip to content

Commit f207a68

Browse files
Github pages
1 parent b8a017c commit f207a68

11 files changed

Lines changed: 1136 additions & 209 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import zio.schema.{DeriveSchema, Schema}
4545
// Domain and state
4646
case class Context(userName: String, greeting: String)
4747
object Context {
48-
implicit val schema: Schema[ScenarioContext] = DeriveSchema.gen[ScenarioContext]
48+
implicit val schema: Schema[Context] = DeriveSchema.gen[Context]
4949
}
5050

5151
// Service

docs/_config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
theme: just-the-docs
2+
title: zio-bdd Documentation
3+
description: Documentation for zio-bdd
4+
url: "https://EtaCassiopeia.github.io/zio-bdd"
Lines changed: 208 additions & 208 deletions
Large diffs are not rendered by default.

docs/advanced-features.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
2+
# Advanced Features in zio-bdd
3+
4+
This page delves into advanced capabilities of `zio-bdd`, including integrating ZIO services, managing complex state, using `ScenarioContext` effectively, and leveraging custom reporters. These features enable you to write sophisticated tests for complex applications.
5+
6+
## Integrating ZIO Services
7+
8+
`zio-bdd` seamlessly integrates with ZIO's dependency injection system via `ZLayer`. This allows you to provide services to your step definitions, making your tests modular and easy to manage.
9+
10+
### Providing Services
11+
12+
In your `ZIOSteps` subclass, override the `environment` method to provide the required services:
13+
14+
```scala
15+
override def environment: ZLayer[Any, Any, Env] =
16+
ZLayer.make[Env](
17+
Service1.live,
18+
Service2.live
19+
)
20+
```
21+
22+
- **Env**: The type of the environment required by your steps (e.g., `Service1 with Service2`).
23+
24+
### Using Services in Steps
25+
26+
Access services in your step definitions using `ZIO.service`:
27+
28+
```scala
29+
When("some action is performed") {
30+
for {
31+
service <- ZIO.service[Service1]
32+
result <- service.doSomething()
33+
// ...
34+
} yield ()
35+
}
36+
```
37+
38+
This approach keeps your tests clean and decoupled from service implementations.
39+
40+
## Managing Complex State
41+
42+
For tests requiring intricate state management, `ScenarioContext` can hold complex data structures. Define a case class to represent your state and provide an implicit `Schema` for serialization.
43+
44+
### Example
45+
46+
```scala
47+
case class ComplexState(users: Map[String, User], currentUser: Option[String])
48+
implicit val schema: Schema[ComplexState] = DeriveSchema.gen[ComplexState]
49+
50+
Given("a user named " / string) { (name: String) =>
51+
for {
52+
state <- ScenarioContext.get
53+
updatedUsers = state.users + (name -> User(name))
54+
_ <- ScenarioContext.update(_.copy(users = updatedUsers))
55+
} yield ()
56+
}
57+
```
58+
59+
- Use `ScenarioContext.update` to modify the state immutably.
60+
61+
## Custom Reporters
62+
63+
While `zio-bdd` provides built-in reporters, you can create custom reporters for specialized output formats.
64+
65+
### Implementing a Custom Reporter
66+
67+
Extend the `Reporter` trait:
68+
69+
```scala
70+
class CustomReporter extends Reporter {
71+
override def report(results: List[FeatureResult]): ZIO[Any, Nothing, Unit] = {
72+
// Custom reporting logic
73+
ZIO.succeed(())
74+
}
75+
}
76+
```
77+
78+
- Register your reporter in the `@Suite` annotation:
79+
80+
```scala
81+
@Suite(reporters = Array("custom"))
82+
object MySpec extends ZIOSteps[Env, State] {
83+
// ...
84+
}
85+
```
86+
87+
- You'll need to map `"custom"` to your `CustomReporter` instance in the test framework configuration.
88+
89+
## Scenario Outlines and Examples
90+
91+
`zio-bdd` fully supports Gherkin’s `Scenario Outline` and `Examples` for data-driven testing.
92+
93+
### Defining Steps for Outlines
94+
95+
Write step definitions as usual, using extractors for placeholders:
96+
97+
```scala
98+
Given("a user named " / string) { (name: String) =>
99+
// ...
100+
}
101+
```
102+
103+
- `zio-bdd` automatically handles the expansion of outlines into multiple scenarios.
104+
105+
## Background Steps
106+
107+
Gherkin’s `Background` section runs before each scenario in a feature. Define steps for background as you would for any other step.
108+
109+
### Example
110+
111+
In your feature file:
112+
113+
```gherkin
114+
Feature: User Management
115+
Background:
116+
Given a system is running
117+
Scenario: Create user
118+
When a user is created
119+
Then the user exists
120+
```
121+
122+
Define the background step:
123+
124+
```scala
125+
Given("a system is running") {
126+
// Setup system
127+
}
128+
```
129+
130+
- Background steps are executed before each scenario, ensuring a consistent starting state.
131+
132+
## Best Practices
133+
134+
- **Service Mocking**: Use test doubles or mocks for services to isolate tests.
135+
- **State Reset**: Ensure each scenario starts with a clean state, especially when using shared resources.
136+
- **Custom Extractors**: For complex parameter types, define custom extractors extending `TypedExtractor`.
137+
138+
## Next Steps
139+
140+
- Explore practical applications in [Examples](examples.md).
141+
- Contribute to `zio-bdd` by checking the [Contribution Guide](contributing.md).

docs/contributing.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
# Contributing to zio-bdd
3+
4+
We welcome contributions to `zio-bdd`! This guide outlines how to get involved, from reporting issues to submitting pull requests. Your contributions help make `zio-bdd` better for the entire community.
5+
6+
## Getting Started
7+
8+
### Reporting Issues
9+
10+
If you encounter bugs, have feature requests, or need clarification, please open an issue on the [GitHub repository](https://github.com/EtaCassiopeia/zio-bdd). When reporting issues:
11+
12+
- **Search First**: Check if the issue already exists.
13+
- **Be Detailed**: Provide steps to reproduce, expected behavior, and actual behavior.
14+
- **Include Versions**: Mention your Scala, ZIO, and `zio-bdd` versions.
15+
16+
### Suggesting Features
17+
18+
Feature suggestions are welcome! When proposing a new feature:
19+
20+
- **Explain the Use Case**: Describe the problem it solves.
21+
- **Consider Alternatives**: Mention any workarounds or existing solutions.
22+
- **Be Open to Discussion**: Engage with the community to refine the idea.
23+
24+
## Development Workflow
25+
26+
### Setting Up the Environment
27+
28+
1. **Fork the Repository**: Create your own fork on GitHub.
29+
2. **Clone Your Fork**:
30+
```bash
31+
git clone https://github.com/your-username/zio-bdd.git
32+
```
33+
3. **Install Dependencies**: Ensure you have Scala 3 and SBT installed.
34+
4. **Build the Project**:
35+
```bash
36+
sbt compile
37+
```
38+
39+
### Making Changes
40+
41+
1. **Create a Branch**:
42+
```bash
43+
git checkout -b feature/your-feature-name
44+
```
45+
2. **Write Code**: Follow the coding standards and add tests for new features.
46+
3. **Run Tests**:
47+
```bash
48+
sbt test
49+
```
50+
4. **Commit Changes**: Use clear, descriptive commit messages.
51+
5. **Push to Your Fork**:
52+
```bash
53+
git push origin feature/your-feature-name
54+
```
55+
56+
### Submitting a Pull Request
57+
58+
1. **Open a Pull Request**: From your fork to the main repository.
59+
2. **Describe Your Changes**: Explain what you did and why.
60+
3. **Link to Issues**: If applicable, reference related issues.
61+
4. **Wait for Review**: Be responsive to feedback and make necessary adjustments.
62+
63+
## Coding Standards
64+
65+
- **Follow Scala Style**: Adhere to the [Scala Style Guide](https://docs.scala-lang.org/style/).
66+
- **Use ZIO Best Practices**: Write idiomatic ZIO code.
67+
- **Document Code**: Add Scaladoc comments for public APIs.
68+
- **Test Thoroughly**: Ensure new features are covered by tests.
69+
70+
## Community Guidelines
71+
72+
- **Be Respectful**: Treat all contributors with kindness and respect.
73+
- **Stay Constructive**: Provide feedback that helps improve the project.
74+
- **Collaborate**: Work together to solve problems and implement features.
75+
76+
## License
77+
78+
By contributing to `zio-bdd`, you agree that your contributions will be licensed under the Apache License 2.0.
79+
80+
Thank you for contributing to `zio-bdd`! Your efforts help advance BDD testing in the Scala and ZIO ecosystems.

0 commit comments

Comments
 (0)