Last active
August 29, 2015 14:00
-
-
Save sawanoboly/11420896 to your computer and use it in GitHub Desktop.
serverspecとCapybaraを一緒に使う ref: http://qiita.com/sawanoboly/items/ddfcb5cac037c15a4052
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -- snip -- | |
| if c.host != host | |
| c.ssh.close if c.ssh | |
| c.host = host | |
| ## ここでCapybara.app_hostを設定しちゃう。 | |
| Capybara.app_host = "http://#{host}" | |
| options = Net::SSH::Config.for(c.host) | |
| user = options[:user] || Etc.getlogin | |
| c.ssh = Net::SSH.start(host, user, options) | |
| end | |
| # -- snip -- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| require 'spec_helper' | |
| ## serverspecのコマンドリソースでopensslのバージョンをチェックする | |
| describe command('openssl version') do | |
| it { should return_stdout /^OpenSSL\ 1\.0\.1g/ } | |
| end | |
| ## `:type => :feature`で`capybara`を使う | |
| describe 'visit Heartbleed test' ,:type => :feature do | |
| before :each do | |
| Capybara.app_host = 'https://filippo.io' | |
| end | |
| ## Heartbleedテストのトップページを表示するテスト | |
| it 'show testpage' do | |
| visit '/Heartbleed/' | |
| expect(page).to have_content 'Heartbleed test' | |
| end | |
| ## google.com(任意)に対してHeartbleedテストを実施して、`All good`が表示されることを確認 | |
| it 'check google ssl' do | |
| visit '/Heartbleed/' | |
| fill_in 'hostname', :with => 'google.com' | |
| click_on 'Go!' | |
| expect(page).to have_content 'All good, google.com seems fixed or unaffected!' | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ rspec -fd --color | |
| Command "openssl version" | |
| should return stdout /^OpenSSL\ 1\.0\.1g/ | |
| visit Heartbleed test | |
| show testpage | |
| check google ssl | |
| Finished in 4.79 seconds | |
| 3 examples, 0 failures |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'serverspec' | |
| require 'capybara/rspec' | |
| require 'capybara-webkit' | |
| include SpecInfra::Helper::Exec | |
| include SpecInfra::Helper::DetectOS | |
| RSpec.configure do |c| | |
| if ENV['ASK_SUDO_PASSWORD'] | |
| require 'highline/import' | |
| c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false } | |
| else | |
| c.sudo_password = ENV['SUDO_PASSWORD'] | |
| end | |
| end | |
| Capybara.default_driver = :webkit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment