お隣のプログラマがとっても幸せそうだったのでチェック!
rspecとrspec-railsは入っているものとしています。
以下を入れます。
sudo gem install nokogiri sudo gem install webrat sudo gem install cucumber sudo gem install term-ansicolor sudo gem install treetop sudo gem diff-lcs
テスト用のプロジェクトを作って確認します。
% rails -d mysql testhoge % cd testhoge % rake db:create:all % ./script/generate cucumber % ./script/generate rspec % ./script/generate rspec_scaffold Post name:string content:text % ./script/generate feature Post name:string content:text % rake db:migrate
feature/以下にファイルができています。
manage_posts.featureとか。
とりあえず実行してみます。
% rake features (in /home/works/code/rails/testhoge) /opt/local/bin/ruby -I "/opt/local/lib/ruby/gems/1.8/gems/cucumber-0.3.0/lib:lib" "/opt/local/lib/ruby/gems/1.8/gems/cucumber-0.3.0/bin/cucumber" --format pretty --require features/step_definitions/post_steps.rb --require features/step_definitions/webrat_steps.rb --require features/support/env.rb --require features/support/paths.rb features/manage_posts.feature Feature: Manage posts In order to [goal] [stakeholder] wants [behaviour] Scenario: Register new post # features/manage_posts.feature:6 Given I am on the new post page # features/step_definitions/webrat_steps.rb:6 When I fill in "Name" with "name 1" # features/step_definitions/webrat_steps.rb:22 And I fill in "Content" with "content 1" # features/step_definitions/webrat_steps.rb:22 And I press "Create" # features/step_definitions/webrat_steps.rb:14 Then I should see "name 1" # features/step_definitions/webrat_steps.rb:93 And I should see "content 1" # features/step_definitions/webrat_steps.rb:93 Scenario: Delete post # features/manage_posts.feature:14 Given the following posts: # features/step_definitions/post_steps.rb:1 | name | content | | name 1 | content 1 | | name 2 | content 2 | | name 3 | content 3 | | name 4 | content 4 | When I delete the 3rd post # features/step_definitions/post_steps.rb:5 Then I should see the following posts: # features/step_definitions/post_steps.rb:12 | name | content | | name 1 | content 1 | | name 2 | content 2 | | name 4 | content 4 | 2 scenarios 9 passed steps
Given~とかWhen~とかは緑色になってました。
動く事を確認できました。
次回は、
- 出力結果を日本語
- feature自体を日本語で書く
ようにしてみたいと思います。