public
Last active

  • Download Gist
.gitignore
1
/output
Gemfile
Ruby
1 2 3 4 5 6 7
source :rubygems
 
gem 'capybara'
gem 'rspec'
 
gem 'axlsx'
gem 'mini_magick'
spec/okayama01_spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# coding: utf-8
require_relative './spec_helper'
 
describe 'http://regional.rubykaigi.org/okayama01' do
before do
visit '/okayama01'
end
 
it 'タイトルに、"岡山Ruby会議01" と表示されていること' do
should have_css('h2', text: '岡山Ruby会議01')
end
 
it 'タイムテーブルが掲載されていること' do
should have_css('h3', text: 'タイムテーブル')
end
 
it 'すでに満員になっており、参加登録できないこと' do
find('.registration_external').click_link('https://ssl.kokucheese.com/event/entry/33608/')
should have_css('#lastmessage', text: '現在、お申し込みはできません。')
should have_css('.alert', text: 'お申し込みが定員に達しました。')
end
end
spec/spec_helper.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
# coding: utf-8
 
require 'capybara/dsl'
 
require 'axlsx'
require 'mini_magick'
 
Capybara.default_driver = :selenium
Capybara.app_host = 'http://regional.rubykaigi.org'
 
RSpec.configure do |config|
config.include Capybara::DSL
 
def excel
@@excel ||= Axlsx::Package.new
end
 
def worksheet_for_spec
@@worksheet_for_spec ||= excel.workbook.add_worksheet(name: 'Spec') do |sheet|
excel.workbook.styles do |style|
black_cell = style.add_style :bg_color => '000000', :fg_color => 'FFFFFF', :sz => 14, :alignment => { :horizontal=> :center }
sheet.add_row %w(検証項目 ○/×), style: black_cell
end
end
end
 
def output_dir
File.join(File.dirname(__FILE__), '..', 'output')
end
 
def serial_number
@@serial_number ||= 0
@@serial_number += 1
end
 
config.after :each do
metadata = self.example.metadata
description = [*metadata[:example_group][:description_args], *metadata[:description_args]].join('-')
 
spec_number = serial_number
 
excel.workbook.styles do |style|
border = style.add_style :border => { :style => :thick, :color =>"AAAAAA" }
worksheet_for_spec.add_row [description, self.example.exception ? '×' : '○'], style: border
end
 
image_src = File.join(output_dir, '%s.png' % [spec_number])
page.driver.browser.save_screenshot(image_src)
 
image_data = MiniMagick::Image.open(image_src)
 
excel.workbook.add_worksheet(name: 'ScreenShot_%s' % [spec_number]) do |sheet|
sheet.add_image(image_src: image_src) do |image|
image.width = image_data[:width]
image.height = image_data[:height]
end
end
end
 
config.after :suite do
excel.use_shared_strings = true # for Numbers
excel.serialize(File.join(output_dir, 'okayama01_spec.xlsx'))
end
end

Setup

$ git clone git://gist.github.com/3062485.git gist-3062485
$ cd gist-3062485
$ bundle install

Run

$ bundle exec rspec

And open output/okayama01_spec.xlsx file.

This gist is a sample for my presentation "capybara で快適なテスト生活を".

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.