LoginSignup
19
19

More than 5 years have passed since last update.

Cucumberの結果をSinatraでホスティング、APIステータスサイトを手軽に実現

Last updated at Posted at 2013-02-02

この記事は最終更新から1年以上経過しています。 気をつけてね。

githubのステータスサイトなど、WebでAPIを提供するプロバイダならユーザから各機能が正常なのかをお知らせしたいですね。

何かの機能がそのふるまいをできているかどうか? これはCucumberの出番ですかね。
最新結果がいつでも誰にでも分かるようになっていればベストですが、そのためのサーバを立てて管理して・・・となると面倒極まりない。

スケジューラもあることだしHerokuにやってもらうか。

今回のサンプルはこちらにおいてます > https://github.com/higanworks/heroku_cuucmber_example

概要

  • cucumberのhtml出力を定期的に実行する
  • 結果のhtmlをherokuでホスティングする

Gemfileの作成

SinatraCucumberなど関連するGemsを入れるためGemfileを作成します、Bundleしておきましょう。Gemfile.lockも忘れずにgitに入れておきます。

Gemfile
source "https://rubygems.org"

gem "sinatra"
gem "cucumber"
gem "rake"
gem "thin"

sinatraでindex.htmlを表示する

/が呼ばれたらpublic/index.htmlのファイルの内容をReadすればいいので、cunfig.ruにまるごと書いてしまえばいいです。

config.ru
require 'sinatra'
get('/') { open('public/index.html').read }
run Sinatra::Application

必要十分。多言語対応ならjaとかenとかのクエリを貰って分岐しますわ。

heroku用にForemanのファイルを用意する

herokuはForemanでアプリを起動してくれるので、foreman用の定義をつくります。

Procfile
web: bundle exec rackup -p $PORT

herokuへ

featuresを適当に書いたら、herokuへアップします。

Shell
heroku create
git push heroku master

cucumberをheroku上で実行

出力をpublic/index.htmlにして更新します。

Shell
heroku run cucumber -f html -o public/index.html

これでindex.htmlがcucumberの出力に差し替わります。

とりあえずホスティングした結果

http://mighty-springs-8010.herokuapp.com/

問題なく見れました。

cucumber_on_heroku

あとは定期的に実行すればOKと。

スケジューラの追加と登録

アプリにスケジューラアドオンを追加します。

Shell
heroku addons:add scheduler:standard

先程のcucumberをタスクに登録すれば定期的にindex.htmlが更新されていきます。

終わりに

出力のフォーマットをカスタマイズして、ユーザへの自動情報提供ページがつくれますね。
ビヘイビアテストとユーザ告知を同時に実現できる、なかなか良い仕組みだと思います。

19
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
19