Using Watir with RSpec and RailsEdit
Installation
See:
- Installing SafariWatir on Mac OS X Tiger
- Installing Spec::UI 0.2.0 on Mac OS X Tiger; or
- Upgrading to Spec::UI 0.2.2 on Mac OS X Tiger
For the latest installation or upgrade notes, see the #rspec tag.
Other setup
There are is no official documentation for setting up and using Spec::UI at this time, but Aslak Hellesoy posted these instructions to the RSpec users mailing list describing the necessary steps.
Similar instructions can also be found here.
Rakefile changes
require 'spec/rake/spectask'
desc "Run in-browser specs"
Spec::Rake::SpecTask.new('spec:ui') do |t|
t.spec_files = FileList['spec/**/*.rb']
t.spec_opts = [
'--require', 'spec/spec_helper',
'--format', 'Spec::Ui::ScreenshotFormatter:spec_report.html',
'--format', 'progress',
]
end
spec_helper.rb
changes
Spec::Runner.configure do |config|
config.include Spec::Matchers::Watir
end
before
and after
blocks
require 'spec/rake/spectask'
desc "Run in-browser specs"
Spec::Rake::SpecTask.new('spec:ui') do |t|
t.spec_files = FileList['spec/**/*.rb']
t.spec_opts = [
'--require', 'spec/spec_helper',
'--format', 'Spec::Ui::ScreenshotFormatter:spec_report.html',
'--format', 'progress',
]
end
spec_helper.rb
changes
Spec::Runner.configure do |config|
config.include Spec::Matchers::Watir
end
before
and after
blocks
All specs will require some special set-up and tear-down:
before(:all) do
@browser = Watir::Browser.new
end
after(:each) do
# needed for screenshots to work
Spec::Ui::ScreenshotFormatter.browser = @browser
end
after(:all) do
@browser.kill! rescue nil
end