Skip to content

Commit

Permalink
[dist] Simplify smoketest spec helper
Browse files Browse the repository at this point in the history
  • Loading branch information
hennevogel committed Mar 23, 2017
1 parent 8754d86 commit 42fc604
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 40 deletions.
51 changes: 28 additions & 23 deletions dist/t/spec/spec_helper.rb
@@ -1,47 +1,52 @@
require 'capybara/dsl'
# OBS Appliance spec helper.
#
# for capybara rspec support
require 'support/capybara'

SCREENSHOT_DIR = "/tmp/rspec_screens"

RSpec.configure do |config|
#rspec-expectations config goes here.
config.expect_with :rspec do |expectations|
# to disable deprecated should syntax
expectations.syntax = :expect
end
config.before(:suite) do
FileUtils.rm_rf(SCREENSHOT_DIR)
FileUtils.mkdir_p(SCREENSHOT_DIR)
end
config.after(:each) do |example|
if example.exception
take_screenshot(example)
dump_page(example)
end
end
# Limits the available syntax to the non-monkey patched
config.disable_monkey_patching!
config.include Capybara::DSL
config.fail_fast = 1
end

# for capybara rspec support
require 'support/capybara'

SCREENSHOT_DIR = "/tmp/rspec_screens"
def dump_page(example)
filename = File.basename(example.metadata[:file_path])
line_number = example.metadata[:line_number]
dump_name = "dump-#{filename}-#{line_number}.html"
dump_path = File.join(SCREENSHOT_DIR, dump_name)
page.save_page(dump_path)
end

def take_screenshot(example)
meta = example.metadata
filename = File.basename(meta[:file_path])
line_number = meta[:line_number]
filename = File.basename(example.metadata[:file_path])
line_number = example.metadata[:line_number]
screenshot_name = "screenshot-#{filename}-#{line_number}.png"
screenshot_path = File.join(SCREENSHOT_DIR, screenshot_name)
page.save_screenshot(screenshot_path)
puts meta[:full_description] + "\n Screenshot: #{screenshot_path}"
end

def obs_login (user,password)

def login
visit "/user/login"
fill_in 'user_login', with: user
fill_in 'user_password', with: password
click_button('Log In »')
first(:link,'Logout')
fill_in 'user_login', with: 'Admin'
fill_in 'user_password', with: 'opensuse'
click_button('log-in-button')

expect(page).to have_link('link-to-user-home')
end

def logout
within("div#subheader") do
click_link('Logout')
end
expect(page).to have_no_link('link-to-user-home')
end
23 changes: 6 additions & 17 deletions dist/t/spec/support/capybara.rb
@@ -1,16 +1,17 @@
require 'capybara'
require 'capybara/dsl'
require 'capybara/poltergeist'
require 'socket'

Capybara.default_max_wait_time = 6

Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, debug: false, timeout: 8)
Capybara::Poltergeist::Driver.new(app, debug: false, timeout: 60)
end

Capybara.default_driver = :poltergeist
Capybara.javascript_driver = :poltergeist
Capybara.save_path = '/tmp/rspec_screens'

# Set hostname
begin
hostname = Socket.gethostbyname(Socket.gethostname).first
rescue SocketError
Expand All @@ -20,21 +21,9 @@
if hostname.empty?
hostname = ipaddress
end
Capybara.app_host = "https://" + hostname

Capybara.app_host = ENV['SMOKETEST_HOST'].nil? ? "https://#{hostname}" : "http://localhost:3000"

# Automatically save the page a test fails
Capybara.save_path = '/tmp'
RSpec.configure do |config|
config.after(:each, type: :feature) do
example_filename = RSpec.current_example.full_description
example_filename = example_filename.tr(' ', '_')
example_filename = example_filename + '.html'
example_filename = File.expand_path(example_filename, Capybara.save_path)
if RSpec.current_example.exception.present?
save_page(example_filename)
elsif File.exist?(example_filename)
File.unlink(example_filename)
end
end
config.include Capybara::DSL
end

0 comments on commit 42fc604

Please sign in to comment.