Module: Capybara::SpecHelper
- Defined in:
- lib/capybara/spec/spec_helper.rb
Class Method Summary collapse
- .configure(config) ⇒ Object
- .filter(requires, metadata) ⇒ Object
- .reset! ⇒ Object
- .run_specs(session, name, options = {}) ⇒ Object
- .spec(name, options = {}, &block) ⇒ Object
Instance Method Summary collapse
- #extract_results(session) ⇒ Object
- #quietly ⇒ Object
-
#silence_stream(stream) ⇒ Object
class << self.
Class Method Details
.configure(config) ⇒ Object
19 20 21 22 23 |
# File 'lib/capybara/spec/spec_helper.rb', line 19 def configure(config) config.filter_run_excluding :requires => method(:filter).to_proc config.before { Capybara::SpecHelper.reset! } config.after { Capybara::SpecHelper.reset! } end |
.filter(requires, metadata) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/capybara/spec/spec_helper.rb', line 38 def filter(requires, ) if requires and [:capybara_skip] requires.any? do |require| [:capybara_skip].include?(require) end else false end end |
.reset! ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/capybara/spec/spec_helper.rb', line 25 def reset! Capybara.app = TestApp Capybara.app_host = nil Capybara.default_selector = :xpath Capybara.default_wait_time = 1 Capybara.ignore_hidden_elements = true Capybara.exact = false Capybara. = false Capybara.raise_server_errors = true Capybara.visible_text_only = false Capybara.match = :smart end |
.run_specs(session, name, options = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/capybara/spec/spec_helper.rb', line 53 def run_specs(session, name, ={}) specs = @specs RSpec.describe Capybara::Session, name, do include Capybara::SpecHelper include Capybara::RSpecMatchers before do @session = session end after do @session.reset_session! end specs.each do |spec_name, , block| describe spec_name, do class_eval(&block) end end end end |
.spec(name, options = {}, &block) ⇒ Object
48 49 50 51 |
# File 'lib/capybara/spec/spec_helper.rb', line 48 def spec(name, ={}, &block) @specs ||= [] @specs << [name, , block] end |
Instance Method Details
#extract_results(session) ⇒ Object
90 91 92 |
# File 'lib/capybara/spec/spec_helper.rb', line 90 def extract_results(session) YAML.load Nokogiri::HTML(session.body).xpath("//pre[@id='results']").first.inner_html.lstrip end |
#quietly ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/capybara/spec/spec_helper.rb', line 82 def quietly silence_stream(STDOUT) do silence_stream(STDERR) do yield end end end |
#silence_stream(stream) ⇒ Object
class << self
73 74 75 76 77 78 79 80 |
# File 'lib/capybara/spec/spec_helper.rb', line 73 def silence_stream(stream) old_stream = stream.dup stream.reopen(RbConfig::CONFIG['host_os'] =~ /rmswin|mingw/ ? 'NUL:' : '/dev/null') stream.sync = true yield ensure stream.reopen(old_stream) end |