update godog usage example with more details
Этот коммит содержится в:
родитель
6e2c1b291a
коммит
a91846c1ab
8 изменённых файлов: 48 добавлений и 23 удалений
64
README.md
64
README.md
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
# Godog
|
# Godog
|
||||||
|
|
||||||
<p align="center"><img src="https://raw.github.com/DATA-DOG/godog/master/logo.png" alt="Godog logo" style="width:250px;" /></p>
|
<p align="center"><img src="/logo.png" alt="Godog logo" style="width:250px;" /></p>
|
||||||
|
|
||||||
**The API is likely to change a few times before we reach 1.0.0**
|
**The API is likely to change a few times before we reach 1.0.0**
|
||||||
|
|
||||||
|
@ -64,15 +64,19 @@ themselves from costly regressions.
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
The following example can be [found
|
The following example can be [found
|
||||||
here](https://github.com/DATA-DOG/godog/tree/master/examples/godogs).
|
here](/examples/godogs).
|
||||||
|
|
||||||
#### Step 1
|
#### Step 1
|
||||||
|
|
||||||
Imagine we have a **godog cart** to serve godogs for dinner. At first, we describe our feature
|
Given we create a new go package **$GOPATH/src/godogs**. From now on, this
|
||||||
in plain text:
|
is our work directory `cd $GOPATH/src/godogs`.
|
||||||
|
|
||||||
|
Imagine we have a **godog cart** to serve godogs for lunch. First of all,
|
||||||
|
we describe our feature in plain text - `vim
|
||||||
|
$GOPATH/src/godogs/features/godogs.feature`:
|
||||||
|
|
||||||
``` gherkin
|
``` gherkin
|
||||||
# file: examples/godogs/godog.feature
|
# file: $GOPATH/src/godogs/features/godogs.feature
|
||||||
Feature: eat godogs
|
Feature: eat godogs
|
||||||
In order to be happy
|
In order to be happy
|
||||||
As a hungry gopher
|
As a hungry gopher
|
||||||
|
@ -87,18 +91,37 @@ Feature: eat godogs
|
||||||
As a developer, your work is done as soon as you’ve made the program behave as
|
As a developer, your work is done as soon as you’ve made the program behave as
|
||||||
described in the Scenario.
|
described in the Scenario.
|
||||||
|
|
||||||
|
**NOTE:** same as **go test** godog respects package level isolation. All
|
||||||
|
your step definitions should be in your tested package root directory. In
|
||||||
|
this case - `$GOPATH/src/godogs`
|
||||||
|
|
||||||
#### Step 2
|
#### Step 2
|
||||||
|
|
||||||
If you run `godog godog.feature` inside the **examples/godogs** directory.
|
If godog is installed in your GOPATH. We can run `godog` inside the
|
||||||
You should see that the steps are undefined:
|
**$GOPATH/src/godogs** directory. You should see that the steps are
|
||||||
|
undefined:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
It gives you undefined step snippets to implement in your test context. You may copy these snippets
|
If we wish to vendor godog dependency, we can do it as usual, using tools
|
||||||
into your `*_test.go` file.
|
you prefer:
|
||||||
|
|
||||||
Now if you run the tests again you should see that the definition is now pending. You may change
|
git clone https://github.com/DATA-DOG/godog.git $GOPATH/src/godogs/vendor/github.com/DATA-DOG/godog
|
||||||
**ErrPending** to **nil** and the scenario will pass successfully.
|
|
||||||
|
It gives you undefined step snippets to implement in your test context.
|
||||||
|
You may copy these snippets into your `godogs_test.go` file.
|
||||||
|
|
||||||
|
Our directory structure should now look like:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
If you copy the snippets into our test file and run godog again. We should
|
||||||
|
see the step definition is now pending:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
You may change **ErrPending** to **nil** and the scenario will
|
||||||
|
pass successfully.
|
||||||
|
|
||||||
Since we need a working implementation, we may start by implementing only what is necessary.
|
Since we need a working implementation, we may start by implementing only what is necessary.
|
||||||
|
|
||||||
|
@ -107,10 +130,10 @@ Since we need a working implementation, we may start by implementing only what i
|
||||||
We only need a number of **godogs** for now. Lets keep it simple.
|
We only need a number of **godogs** for now. Lets keep it simple.
|
||||||
|
|
||||||
``` go
|
``` go
|
||||||
/* file: examples/godogs/godog.go */
|
/* file: $GOPATH/src/godogs/godogs.go */
|
||||||
package main
|
package main
|
||||||
|
|
||||||
// Godogs to eat
|
// Godogs available to eat
|
||||||
var Godogs int
|
var Godogs int
|
||||||
|
|
||||||
func main() { /* usual main func */ }
|
func main() { /* usual main func */ }
|
||||||
|
@ -122,7 +145,7 @@ Now lets implement our step definitions, which we can copy from generated
|
||||||
console output snippets in order to test our feature requirements:
|
console output snippets in order to test our feature requirements:
|
||||||
|
|
||||||
``` go
|
``` go
|
||||||
/* file: examples/godogs/godog_test.go */
|
/* file: $GOPATH/src/godogs/godogs_test.go */
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -162,9 +185,9 @@ func FeatureContext(s *godog.Suite) {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Now when you run the `godog godog.feature` again, you should see:
|
Now when you run the `godog` again, you should see:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
**Note:** we have hooked to **BeforeScenario** event in order to reset state. You may hook into
|
**Note:** we have hooked to **BeforeScenario** event in order to reset state. You may hook into
|
||||||
more events, like **AfterStep** to test against an error and print more details about the error
|
more events, like **AfterStep** to test against an error and print more details about the error
|
||||||
|
@ -182,12 +205,13 @@ See `godog -h` for general command options.
|
||||||
|
|
||||||
See implementation examples:
|
See implementation examples:
|
||||||
|
|
||||||
- [rest API server](https://github.com/DATA-DOG/godog/tree/master/examples/api)
|
- [rest API server](/examples/api)
|
||||||
- [godogs](https://github.com/DATA-DOG/godog/tree/master/examples/godogs)
|
- [rest API with Database](/examples/db)
|
||||||
|
- [godogs](/examples/godogs)
|
||||||
|
|
||||||
### FAQ
|
### FAQ
|
||||||
|
|
||||||
**Q:** Where can I configure common options globally?
|
**Q:** Where can I configure common options globally?
|
||||||
**A:** You can't. Alias your common or project based commands: `alias godog-wip="godog --format=progress --tags=@wip"`
|
**A:** You can't. Alias your common or project based commands: `alias godog-wip="godog --format=progress --tags=@wip"`
|
||||||
|
|
||||||
### Contributions
|
### Contributions
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# file: $GOPATH/godogs/features/godogs.feature
|
||||||
Feature: eat godogs
|
Feature: eat godogs
|
||||||
In order to be happy
|
In order to be happy
|
||||||
As a hungry gopher
|
As a hungry gopher
|
|
@ -1,7 +1,7 @@
|
||||||
/* file: examples/godogs/godog.go */
|
/* file: $GOPATH/src/godogs/godogs.go */
|
||||||
package main
|
package main
|
||||||
|
|
||||||
// Godogs to eat
|
// Godogs available to eat
|
||||||
var Godogs int
|
var Godogs int
|
||||||
|
|
||||||
func main() { /* usual main func */ }
|
func main() { /* usual main func */ }
|
|
@ -1,4 +1,4 @@
|
||||||
/* file: examples/godogs/godog_test.go */
|
/* file: $GOPATH/src/godogs/godogs_test.go */
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
Двоичные данные
screenshots/dir-tree.png
Обычный файл
Двоичные данные
screenshots/dir-tree.png
Обычный файл
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 25 КиБ |
Двоичные данные
screenshots/passed.png
Двоичные данные
screenshots/passed.png
Двоичный файл не отображается.
До Ширина: | Высота: | Размер: 80 КиБ После Ширина: | Высота: | Размер: 58 КиБ |
Двоичные данные
screenshots/pending.png
Обычный файл
Двоичные данные
screenshots/pending.png
Обычный файл
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 56 КиБ |
Двоичные данные
screenshots/undefined.png
Двоичные данные
screenshots/undefined.png
Двоичный файл не отображается.
До Ширина: | Высота: | Размер: 105 КиБ После Ширина: | Высота: | Размер: 91 КиБ |
Загрузка…
Создание таблицы
Сослаться в новой задаче