Showing posts with label cucumber. Show all posts
Showing posts with label cucumber. Show all posts

Wednesday, October 28, 2009

Cucumber Watir Rspec Mocha, How to add helper module to cucumber.

Cucumber with Watir



# features/support/env.rb
require 'spec/expectations'

if ENV['FIREWATIR']
require 'firewatir'
Browser = FireWatir::Firefox
else
case RUBY_PLATFORM
when /darwin/
require 'safariwatir'
Browser = Watir::Safari
when /win32|mingw/
require 'watir'
Browser = Watir::IE
when /java/
require 'celerity'
Browser = Celerity::Browser
else
raise "This platform is not supported (#{PLATFORM})"
end
end

# "before all"
browser = Browser.new

Before do
@browser = browser
end

# "after all"
at_exit do
browser.close
end


How to add helper modlue



# features/support/foo_helper.rb
module Foo
def zip_code(pref_name)
if pref_name == 'local'
"123-4567"
else
"Pls. ask postman"
end
end
end
World(Foo)


mocha integration.



# features/support/mocha_helper.rb
require "mocha"

World(Mocha::API)

Before do
mocha_setup
end

After do
begin
mocha_verify
ensure
mocha_teardown
end
end

日本語のFeatureの場合、win32 コンソールではひどいが、htmlに結果を出力すればOK。
例えば、

# config/cucumber.yml
default: --format profile features
html_report: --format progress --format html --out=features_report.html features

で、
C:\あ>cucumber -l ja --profile html_report features/send_tera_mail.feature
で実行すれば、ブラウザでは文字化けしない。
他のサイトでもいろいろ試しているようだけど、コンソールではきびしい。