Skip to content

Commit 2701b49

Browse files
authored
docs: rewrite the readme and add a contributing guide (#83)
The README was a mix of usage docs and stale notes, with links pointing at `master`. It is now just what a user of the plugin needs: what it does, what it requires, where tests go, and what a passing test looks like. Everything a contributor needs moved to CONTRIBUTING.md, modelled on the one in test-kitchen/busser -- how to set the project up, how to run the suite, the linters CI runs, and the Conventional Commits convention release-please reads. Every development dependency now carries a version floor at its current major, so a resolver cannot quietly pick an ancient release: cookstyle 9, aruba 2.4, cucumber 11.1, rake 13.4, serverspec 2.43, simplecov 1.1. Test tooling brought up to date: * `.rubocop.yml` targeted Ruby 3.1 while the gemspec requires 3.2. * The `After` hook setting `Cucumber.wants_to_quit` is replaced by cucumber's own `--fail-fast`, which is the supported way to stop at the first failure. * `-x` (`--expand`) is dropped; it only affects Scenario Outline output and there are no outlines here. Two notes specific to this repository: **CONTRIBUTING.md was not a contributing guide.** It held a notice recommending kitchen-verifier-shell instead of this plugin. That is useful information for a user, not a contributor, so it has moved into the README's Status section alongside the archival notice, and CONTRIBUTING.md is now an actual contributing guide. **The documented file layout was wrong.** The README said the glob was `serverspec/*/*_spec.rb` and that specs must sit exactly one directory deep. The runner has used `**/*_spec.rb` since the RSpec 3 support landed, so any depth works and the `localhost/` directory is convention rather than a requirement. `.tailor` is removed. It configured the tailor gem, unmaintained since 2014 and not in the bundle, so the file did nothing. Signed-off-by: Tim Smith <tsmith84@proton.me>
1 parent d3a3c59 commit 2701b49

7 files changed

Lines changed: 190 additions & 64 deletions

File tree

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ require:
33
- cookstyle/chefstyle
44

55
AllCops:
6-
TargetRubyVersion: 3.1
6+
TargetRubyVersion: 3.2
77
Exclude:
88
- "vendor/**/*"
99
- "spec/**/*"

.tailor

Lines changed: 0 additions & 6 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 102 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,104 @@
1-
# Notice
1+
# Contributing to busser-serverspec
22

3-
You should use [Kitchen::Verifier::Shell](https://github.com/higanworks/kitchen-verifier-shell) + [Serverspec](http://serverspec.org/) instead of Busser::RunnerPlugin::Serverspec.
3+
Thanks for taking the time to contribute. This document covers how to get the
4+
project running locally, how to check your work before opening a pull request,
5+
and the commit convention releases depend on.
46

5-
* [Official Document](https://github.com/test-kitchen/test-kitchen/pull/741) (This PR has been merged. You can use this with Test Kitchen 1.5.0)
6-
* [Cookbook testing by Serverspec with Shell Verifier of Test Kitchen](http://www.creationline.com/en/lab/12161) ([Japanese](http://www.creationline.com/lab/12161))
7+
## Getting set up
8+
9+
This plugin requires **Ruby 3.2 or newer**. Clone the repository and install the
10+
development dependencies:
11+
12+
```bash
13+
git clone https://github.com/test-kitchen/busser-serverspec.git
14+
cd busser-serverspec
15+
bundle install
16+
```
17+
18+
## Running the tests
19+
20+
`rake` runs the whole suite:
21+
22+
```bash
23+
bundle exec rake test
24+
```
25+
26+
The tests are [cucumber](https://cucumber.io) features in `features/`. They
27+
drive the real `busser` executable through
28+
[aruba](https://github.com/cucumber/aruba) rather than calling the plugin's
29+
classes, so they cover it end to end: install the plugin into a throwaway
30+
Busser root, write a suite, run it, and check what came out. The step
31+
definitions they use are published by busser itself, in `lib/busser/cucumber.rb`.
32+
33+
### How the feature sandbox works
34+
35+
Features that install the plugin sandbox `GEM_HOME` into a temporary directory
36+
and strip bundler out of the environment, so a run never installs a gem into
37+
your bundle. Two details matter if you add or change one:
38+
39+
* **Do not reintroduce bundler variables.** RubyGems re-requires
40+
`bundler/setup` whenever `BUNDLER_SETUP` is present, and bundler then resets
41+
`Gem.dir` to the bundle. Plugins install into `vendor/bundle` instead of the
42+
sandbox, and the assertions that look in `GEM_HOME` fail. The
43+
`a non bundler environment` step exists to clear this.
44+
* **The plugin is installed from the working tree.** With bundler out of the
45+
way, `busser plugin install` would fetch the last release from RubyGems and
46+
run *its* postinstall — so the suite would pass on code that is not in your
47+
branch. The `this plugin is installed from the working tree` step builds the
48+
gem from the gemspec and installs it into the sandbox first, which is what
49+
makes the features test your change.
50+
51+
## Linting
52+
53+
CI runs three linters, all of which you can run locally:
54+
55+
```bash
56+
bundle exec cookstyle --chefstyle # Ruby
57+
yamllint --strict . # YAML
58+
markdownlint-cli2 "**/*.md" "!**/CHANGELOG*.md"
59+
```
60+
61+
## Commit messages
62+
63+
This project uses [Conventional Commits](https://www.conventionalcommits.org).
64+
Releases are automated, and the commit subject on `main` is what decides the
65+
next version number and what appears in the changelog.
66+
67+
Pull requests are **squash merged, so the pull request title becomes that
68+
subject**. A CI check enforces the format on the title; the individual commits
69+
on your branch are not checked.
70+
71+
| Prefix | Effect on the next release |
72+
| --- | --- |
73+
| `fix:` | Patch version bump |
74+
| `feat:` | Minor version bump |
75+
| `feat!:`, or a `BREAKING CHANGE:` footer | Minor bump, until this gem reaches 1.0 |
76+
| `chore:`, `docs:`, `ci:`, `test:`, `refactor:` | No release |
77+
78+
For example:
79+
80+
```text
81+
fix: install the plugin into GEM_HOME rather than the bundle
82+
feat: support a Gemfile alongside the suite
83+
ci: pin the shared workflow to a release
84+
```
85+
86+
## Opening a pull request
87+
88+
1. Fork the repository and create a branch for your change.
89+
2. Add or update tests. A bug fix should come with a test that fails without it.
90+
3. Run `bundle exec rake test` and the linters above.
91+
4. Open a pull request with a Conventional Commits title.
92+
93+
## Releases
94+
95+
Releases are handled by
96+
[release-please](https://github.com/googleapis/release-please). It watches
97+
commits landing on `main` and keeps a release pull request open with the next
98+
version number and the accumulated changelog. Merging that pull request tags the
99+
release and publishes the gem to RubyGems and GitHub Packages.
100+
101+
Maintainers do not bump `lib/busser/serverspec/version.rb` or edit
102+
`CHANGELOG.md` by hand; release-please owns both files. This gem is still pre-1.0, so
103+
`bump-minor-pre-major` is set and a breaking change takes the minor rather than
104+
graduating it to 1.0.

Gemfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ source "https://rubygems.org"
33
gemspec
44

55
group :cookstyle do
6-
gem "cookstyle", ">= 9.0.0"
6+
gem "cookstyle", ">= 9.0"
77
end
88

99
group :test do
10-
gem "aruba", ">= 2.0"
11-
gem "base64" # cucumber needs it; not a default gem on Ruby 4.0
10+
gem "aruba", ">= 2.4"
11+
gem "base64", ">= 0.3" # cucumber needs it; not a default gem on Ruby 4.0
1212
gem "cucumber", ">= 11.1"
13-
gem "rake"
13+
gem "rake", ">= 13.4"
1414
gem "serverspec", ">= 2.43"
1515
end
1616

1717
group :development do
18-
gem "simplecov"
18+
gem "simplecov", ">= 1.1"
1919
end

README.md

Lines changed: 77 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,110 @@
1-
# Busser::RunnerPlugin::Serverspec
1+
# busser-serverspec
22

3+
[![Gem Version](https://badge.fury.io/rb/busser-serverspec.svg)](https://badge.fury.io/rb/busser-serverspec)
34

4-
A Busser runner plugin for Serverspec
5+
A [Busser](https://github.com/test-kitchen/busser) runner plugin that runs
6+
[Serverspec](https://serverspec.org) tests as integration tests.
7+
8+
Busser installs Serverspec on the machine under test the first time a suite
9+
runs, then executes the suite's `serverspec` directory against it. Because the
10+
tests run on the machine itself, they use Serverspec's `exec` backend rather
11+
than SSH.
512

613
## Status
714

8-
This Gem has now been archived. No active maintainers have come forward in the past 5 years and the original maintainer has since pulled the plugin.
15+
This gem has been archived. No active maintainers have come forward in the past
16+
five years and the original maintainer has since pulled the plugin.
17+
18+
We recommend moving to a maintained project for similar functionality, or
19+
building and running the gem yourself. In particular,
20+
[kitchen-verifier-shell](https://github.com/higanworks/kitchen-verifier-shell)
21+
with Serverspec covers the same ground and is configured directly in your
22+
`kitchen.yml`.
23+
24+
## Requirements
925

10-
We recommend moving to a maintained project for similar functionality or building and running the Gem yourself.
26+
Ruby 3.2 or newer, and busser 0.9.0 or newer.
1127

12-
## Installation and Setup
28+
## Installation
1329

14-
Put this into your `kitchen.yml`:
30+
Select the Busser verifier in your `kitchen.yml`:
1531

1632
```yaml
1733
verifier:
1834
name: busser
1935
```
2036
21-
You may also look at the Busser [plugin usage][plugin_usage] page.
37+
Busser then installs the plugin for you when the suite runs. To install it by
38+
hand:
39+
40+
```bash
41+
busser plugin install busser-serverspec
42+
```
2243

2344
## Usage
2445

25-
Please put test files into [COOKBOOK]/test/integration/[SUITES]/serverspec/
26-
27-
```cookbook
28-
`-- test
29-
`-- integration
30-
`-- default
31-
`-- serverspec
32-
|-- Gemfile
33-
|-- localhost
34-
| `-- httpd_spec.rb
35-
`-- spec_helper.rb
46+
Put your specs in a subdirectory of the suite's `serverspec` directory:
47+
48+
```text
49+
test
50+
`-- integration
51+
`-- default # suite name
52+
`-- serverspec
53+
|-- Gemfile # optional
54+
|-- spec_helper.rb
55+
`-- localhost
56+
`-- httpd_spec.rb
3657
```
3758

38-
`Gemfile` is optional. You can specify installing Serverspec version and install the gems you need.
39-
40-
## Note
59+
Specs are collected recursively as `**/*_spec.rb`, so any depth works; the
60+
`localhost/` directory above is convention, not a requirement. The separator is
61+
an underscore — `_spec.rb`, not `-spec.rb`. The suite directory is also added to
62+
the load path and set as RSpec's default path, so `require "spec_helper"` works
63+
without a relative path.
4164

42-
### File Matching
65+
```ruby
66+
require "spec_helper"
4367

44-
The globbing pattern to match files is `"serverspec/*/*_spec.rb"`.
45-
You need to use `"_spec.rb"` (underscore), not `"-spec.rb"` (minus).
68+
describe command("echo hello") do
69+
its(:exit_status) { should eq 0 }
70+
its(:stdout) { should eq "hello\n" }
71+
end
72+
```
4673

47-
### Specify Serverspec version
74+
### Backend
4875

49-
If you have to specify the Serverspec version, you can use Gemfile. Example Gemfile:
76+
The tests run on the machine under test, after Test Kitchen has logged in, so
77+
the `exec` backend is the right one:
5078

51-
```Gemfile
52-
source 'https://rubygems.org'
53-
gem 'serverspec', '< 2.0'
79+
```ruby
80+
require "serverspec"
81+
set :backend, :exec
5482
```
5583

56-
### Serverspec backend
84+
Do not use `set :backend, :ssh` — that would have Serverspec connect back out
85+
over the network from a machine that is already the target.
86+
87+
### Pinning Serverspec
88+
89+
A `Gemfile` in the suite directory is `bundle install`ed before the run, which
90+
is how you pin a particular Serverspec version:
91+
92+
```ruby
93+
source "https://rubygems.org"
94+
95+
gem "serverspec", "~> 2.43"
96+
```
5797

58-
It runs on a target server for testing after ssh log in it.
59-
So you need to specify `set :backend, :exec` not `set :backend, :ssh` (Serverspec v2).
60-
If you use Serverspec v1, you must specify `include SpecInfra::Helper::Exec` not `include SpecInfra::Helper::Ssh`.
98+
Without one, the plugin installs Serverspec 2.43 or newer.
6199

62-
## Authors
100+
## Contributing
63101

64-
Created and maintained by [HIGUCHI Daisuke][author] (<d-higuchi@creationline.com>)
102+
Bug reports and pull requests are welcome. See
103+
[CONTRIBUTING.md](CONTRIBUTING.md) for how to set up the project, run the test
104+
suite, and format your commits.
65105

66106
## License
67107

68-
Apache 2.0 (see [LICENSE][license])
108+
Apache License 2.0. See [LICENSE](LICENSE).
69109

70-
[author]: https://github.com/cl-lab-k
71-
[license]: https://github.com/test-kitchen/busser-serverspec/blob/master/LICENSE
72-
[plugin_usage]: https://kitchen.ci/docs/verifiers/serverspec/
110+
Originally created by [HIGUCHI Daisuke](https://github.com/cl-lab-k).

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require "bundler/gem_tasks"
22
require "cucumber/rake/task"
33

44
Cucumber::Rake::Task.new(:features) do |t|
5-
t.cucumber_opts = ["features", "-x", "--format progress"]
5+
t.cucumber_opts = ["features", "--format progress", "--fail-fast"]
66
end
77

88
desc "Run all test suites"

features/support/env.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
if ENV["COVERAGE"]
88
require "simplecov"
99
SimpleCov.command_name "features"
10-
SimpleCov.start
10+
SimpleCov.start do
11+
add_filter "/features/"
12+
add_group "Libraries", "/lib/"
13+
end
1114
end
1215

1316
# aruba 2 dropped @aruba_timeout_seconds; setting it in a Before hook is a
@@ -17,13 +20,6 @@
1720
config.exit_timeout = 120
1821
end
1922

20-
After do |s|
21-
# Tell Cucumber to quit after this scenario is done - if it failed.
22-
# This is useful to inspect the 'tmp/aruba' directory before any other
23-
# steps are executed and clear it out.
24-
Cucumber.wants_to_quit = true if s.failed?
25-
end
26-
2723
# The sandboxed features shell out to `busser plugin install <this plugin>`, and
2824
# two things have to hold for that to exercise this checkout:
2925
#

0 commit comments

Comments
 (0)