How we are writing user perspective tests using tools rspec, capybara, kameleon. To get more readable & maintaiable integration and acceptance tests .
https://github.com/cs3b/kameleon
52. click "Products"
within('table.index) do
see :ordered => [ "apache baseball cap",
"zomg shirt" ]
end
click "admin_products_listing_name_title"
within('table.index') do
see :ordered => [ "zomg shirt",
"apache baseball cap"]
end
62. act_as(:user) do
not_see 'IS OPEN',
'IS CLOSED'
within(:right_column) do
not_see 'Submit a proposal',
'Submit'
end
end
63. act_as(:admin) do
within(:menu) { click 'Set Contest' }
fill_in 'S vs C' => 'Name',
'2012-01-19 08:00:00' => 'starts at',
'2012-01-20 08:00:00' => 'ends at'
click 'Create Contest'
see 'Contest was successfully created'
end
64. Timecop.travel(2012, 1, 19, 8, 59, 55) do
act_as(:user) do
refresh_page
see 'IS CLOSED'
sleep 10
not_see 'IS CLOSED'
see 'IS OPEN'
end
end
65. Timecop.travel(2012, 1, 19, 9, 1, 1) do
act_as(:user) do
refresh_page
%w(ruby ... haml).each do |content|
fill_in content => 'proposal_content'
click 'Submit'
end
end
66. act_as(:admin) do
click 'Sticker proposals',
'Load more'
%w(ruby ... html).each do |c|
within(:proposal_with_content => c) do
click 'favorite'
end
end
end
67. act_as(:user) do
refresh_page
%w(...).each_with_index do |c, r|
within(:proposal_with_content => c) do
click "Rate #{r+1} out of 5"
end
end
end
68. act_as(:user) do
%w(ruby coffescript).each do |c|
within(:proposal_with_content => c) do
click 'Comment'
fill_in "sample text #{c}" => 'body'
click 'Create comment'
end
end
end
69. Timecop.travel(2012, 1, 20, 11, 10, 10) do
act_as(:admin) do
refresh_page
click 'Load more'
%w(html python).each do |c|
within(:proposal_with_content => c) do
click 'choose'
end
end
end
70. act_as(:user) do
refresh_page
click 'Gallery'
within(:ordered_list) do
see *(%w(html python))
not_see *(%w(ruby ... coffescript))
end
end
71. act_as(:admin) do
click 'Gallery', 'Add new production picture'
fill_in 'Sample title for picture' => 'Title',
:attach => {'pict.jpg' => 'Image'}
click 'Create Gallery image'
end
72. act_as(:user) do
click 'Gallery'
fill_in :select => {'S vs C' => 'contest_id'}
within(:gallery_list) do
see :image => 'Thumb_pict'
end
end
73. act_as(:admin) do
click 'Add new contest sticker'
fill_in 'Sample title for picture' => 'Title',
:attach => {'pict2.jpg' => 'Image'}
click 'Create Gallery image'
end
74. act_as(:user) do
click 'Gallery'
fill_in :select => {'S vs C' => 'contest_id'}
within(:gallery_list) do
see :image => 'Thumb_pict2'
end
end
78. SHARED DB CONNECTION
example: lib/kameleon/ext/active_record/
● shared_single_connection.rb
● shared_single_connection_with_spork.rb
79. HEADLESS
RSpec.configure do |config|
config.before(:suite) do
@headless = Headless.new(:display => '100')
@headless.start
end
config.after(:suite) do
@headless.stop if defined?(@headless)
end
end
require 'kameleon/ext/rspec/headless'
80. RIPL
config.after(:each) do
if exception = example.instance_variable_get(:@exception)
Ripl.start :binding => binding
end
end
example: lib/kameleon/utils/debug_console.rb