#!/bin/sh

if [ -z "$ADTTMP" ]; then
  ADTTMP=$(mktemp -d)
  cleanup() {
    rm -rf "$ADTTMP"
  }
  trap cleanup INT TERM EXIT
fi

cd $ADTTMP

exec 2>&1
set -ex

rails new myapp
cd myapp

rails generate cucumber:install

tee features/test.feature <<FEATURE
Feature: test
  Scenario: test
    When I go to /
    Then I should see "Hello, world"
FEATURE

tee features/step_definitions/test_steps.rb <<STEPS
When(/^I go to \/$/) do
  visit '/'
end

Then(/^I should see "([^"]*)"$/) do |arg1|
  expect(page.body).to match(arg1)
end
STEPS

rails generate controller home

tee config/routes.rb <<ROUTES
Rails.application.routes.draw do
  root 'home#index'
end
ROUTES

tee app/views/home/index.html.erb <<HOMEPAGE
Hello, world
HOMEPAGE

rake
