Welcome to mirror list, hosted at ThFree Co, Russian Federation.

matchers.rb « support « features - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 931336234cea31737c00194c56e44a48e29117fd (plain)
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
# frozen_string_literal: true

RSpec::Matchers.define :have_path do |expected|
  match do |actual|
    await_condition { actual.current_path == expected }
  end

  failure_message_for_should do |actual|
    "expected #{actual.inspect} to have path #{expected.inspect} but was #{actual.current_path.inspect}"
  end
  failure_message_for_should_not do |actual|
    "expected #{actual.inspect} to not have path #{expected.inspect} but it had"
  end
end

RSpec::Matchers.define :have_path_in do |expected|
  match do |actual|
    await_condition { expected.include? actual.current_path }
  end

  failure_message_for_should do |actual|
    "expected #{actual.inspect} to have path in #{expected.inspect} but was #{actual.current_path.inspect}"
  end
  failure_message_for_should_not do |actual|
    "expected #{actual.inspect} to not have path in #{expected.inspect} but it had"
  end
end

RSpec::Matchers.define :have_value do |expected|
  match do |actual|
    await_condition { actual.value && actual.value.include?(expected) }
  end

  failure_message_for_should do |actual|
    "expected #{actual.inspect} to have value #{expected.inspect} but was #{actual.value.inspect}"
  end
  failure_message_for_should_not do |actual|
    "expected #{actual.inspect} to not have value #{expected.inspect} but it had"
  end
end

RSpec::Matchers.define :have_js_defined do |expected|
  match do |actual|
    await_condition { actual.evaluate_script("#{expected} !== undefined") == true }
  end

  failure_message_for_should do |actual|
    "expected #{actual.inspect} to have a value for #{expected.inspect} in Javascript but it did not"
  end
  failure_message_for_should_not do |actual|
    "expected #{actual.inspect} to not have a value for #{expected.inspect} in Javascript but it had"
  end
end

def await_condition &condition
  start_time = Time.zone.now
  until condition.call
    return false if (Time.zone.now - start_time) > Capybara.default_max_wait_time
    sleep 0.05
  end
  true
end