Class: RSpec::PageRegression::FilePaths

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/page-regression/file_paths.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example, expected_path = nil) ⇒ FilePaths

Returns a new instance of FilePaths.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rspec/page-regression/file_paths.rb', line 9

def initialize(example, expected_path = nil)
  expected_path = Pathname.new(expected_path) if expected_path

  descriptions = description_ancestry(example.[:example_group])
  descriptions.push example.description unless example.description.parameterize('_') =~ %r{
    ^
    (then_+)?
    ( (expect_+) (page_+) (to_+) (not_+)? | (page_+) (should_+)? )
    match_expectation
    (_#{Regexp.escape(expected_path.to_s)})?
      $
  }xi
  canonical_path = descriptions.map{|s| s.parameterize('_')}.inject(Pathname.new(""), &:+)

  app_root = Pathname.new(example.[:file_path]).realpath.each_filename.take_while{|c| c != "spec"}.inject(Pathname.new("/"), &:+)
  expected_root = app_root + "spec" + "expectation"
  test_root = app_root + "tmp" + "spec" + "expectation"
  cwd = Pathname.getwd

  @expected_image = expected_path || (expected_root + canonical_path + "expected.png").relative_path_from(cwd)
  @test_image = (test_root + canonical_path + "test.png").relative_path_from cwd
  @difference_image = (test_root + canonical_path + "difference.png").relative_path_from cwd
end

Instance Attribute Details

#difference_imageObject (readonly)

Returns the value of attribute difference_image.



7
8
9
# File 'lib/rspec/page-regression/file_paths.rb', line 7

def difference_image
  @difference_image
end

#expected_imageObject (readonly)

Returns the value of attribute expected_image.



5
6
7
# File 'lib/rspec/page-regression/file_paths.rb', line 5

def expected_image
  @expected_image
end

#test_imageObject (readonly)

Returns the value of attribute test_image.



6
7
8
# File 'lib/rspec/page-regression/file_paths.rb', line 6

def test_image
  @test_image
end

Instance Method Details

#allObject



33
34
35
# File 'lib/rspec/page-regression/file_paths.rb', line 33

def all
  [test_image, expected_image, difference_image]
end