capybara-screenshot-nocolor 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +17 -0
  5. data/Appraisals +31 -0
  6. data/CHANGELOG.md +198 -0
  7. data/Gemfile +7 -0
  8. data/LICENSE +19 -0
  9. data/README.md +240 -0
  10. data/Rakefile +40 -0
  11. data/capybara-screenshot.gemspec +38 -0
  12. data/gemfiles/cucumber.1.2.gemfile +9 -0
  13. data/gemfiles/cucumber.1.3.0.gemfile +9 -0
  14. data/gemfiles/latest.gemfile +8 -0
  15. data/gemfiles/rspec.2.14.gemfile +9 -0
  16. data/gemfiles/rspec.2.99.gemfile +9 -0
  17. data/gemfiles/rspec.3.0.gemfile +9 -0
  18. data/gemfiles/spinach.0.7.gemfile +9 -0
  19. data/gemfiles/spinach.0.8.0.gemfile +9 -0
  20. data/lib/capybara-screenshot.rb +157 -0
  21. data/lib/capybara-screenshot/capybara.rb +28 -0
  22. data/lib/capybara-screenshot/cucumber.rb +27 -0
  23. data/lib/capybara-screenshot/minitest.rb +27 -0
  24. data/lib/capybara-screenshot/pruner.rb +47 -0
  25. data/lib/capybara-screenshot/rspec.rb +92 -0
  26. data/lib/capybara-screenshot/rspec/base_reporter.rb +21 -0
  27. data/lib/capybara-screenshot/rspec/html_embed_reporter.rb +25 -0
  28. data/lib/capybara-screenshot/rspec/html_link_reporter.rb +37 -0
  29. data/lib/capybara-screenshot/rspec/text_reporter.rb +38 -0
  30. data/lib/capybara-screenshot/rspec/textmate_link_reporter.rb +19 -0
  31. data/lib/capybara-screenshot/saver.rb +87 -0
  32. data/lib/capybara-screenshot/spinach.rb +26 -0
  33. data/lib/capybara-screenshot/testunit.rb +39 -0
  34. data/lib/capybara-screenshot/version.rb +5 -0
  35. data/spec/cucumber/cucumber_spec.rb +93 -0
  36. data/spec/cucumber/step_definitions/step_definitions.rb +18 -0
  37. data/spec/cucumber/support/env.rb +17 -0
  38. data/spec/feature/minitest_spec.rb +110 -0
  39. data/spec/feature/testunit_spec.rb +81 -0
  40. data/spec/rspec/rspec_spec.rb +159 -0
  41. data/spec/spec_helper.rb +29 -0
  42. data/spec/spinach/spinach_spec.rb +64 -0
  43. data/spec/spinach/support/spinach_failure.rb +41 -0
  44. data/spec/support/common_setup.rb +59 -0
  45. data/spec/support/html_reporter_context.rb +28 -0
  46. data/spec/support/test_app.rb +13 -0
  47. data/spec/unit/base_reporter_spec.rb +25 -0
  48. data/spec/unit/capybara-screenshot_rspec_spec.rb +48 -0
  49. data/spec/unit/capybara-screenshot_spec.rb +88 -0
  50. data/spec/unit/capybara_spec.rb +50 -0
  51. data/spec/unit/pruner_spec.rb +108 -0
  52. data/spec/unit/rspec_reporters/html_embed_reporter_spec.rb +18 -0
  53. data/spec/unit/rspec_reporters/html_link_reporter_spec.rb +27 -0
  54. data/spec/unit/rspec_reporters/text_reporter_spec.rb +97 -0
  55. data/spec/unit/rspec_reporters/textmate_link_reporter_spec.rb +39 -0
  56. data/spec/unit/saver_spec.rb +282 -0
  57. metadata +247 -0
@@ -0,0 +1,18 @@
1
+ When(/^I click on a missing link$/) do
2
+ click_on "you'll never find me"
3
+ end
4
+
5
+ When(/^I click on a missing link on a different page in a different session$/) do
6
+ using_session :different_session do
7
+ visit '/different_page'
8
+ click_on "you'll never find me"
9
+ end
10
+ end
11
+
12
+ When(/^I visit "([^"]*)"$/) do |path|
13
+ visit path
14
+ end
15
+
16
+ Then(/^I trigger an unhandled exception/) do
17
+ raise "you can't handle me"
18
+ end
@@ -0,0 +1,17 @@
1
+ require 'capybara/cucumber'
2
+ require 'capybara-screenshot'
3
+ require 'capybara-screenshot/cucumber'
4
+ require 'aruba/cucumber'
5
+ require 'aruba/jruby'
6
+
7
+ Capybara::Screenshot.register_filename_prefix_formatter(:cucumber) do |fault|
8
+ 'my_screenshot'
9
+ end
10
+
11
+ Before do
12
+ @aruba_timeout_seconds = 60
13
+ end if RUBY_PLATFORM == 'java'
14
+
15
+ After('@restore-capybara-default-session') do
16
+ Capybara.session_name = nil
17
+ end
@@ -0,0 +1,110 @@
1
+ require "spec_helper"
2
+
3
+ describe "Using Capybara::Screenshot with MiniTest" do
4
+ include CommonSetup
5
+
6
+ before do
7
+ clean_current_dir
8
+ end
9
+
10
+ def run_failing_case(code)
11
+ write_file('test_failure.rb', <<-RUBY)
12
+ #{ensure_load_paths_valid}
13
+ require 'minitest/autorun'
14
+ require 'capybara'
15
+ require 'capybara-screenshot'
16
+ require 'capybara-screenshot/minitest'
17
+
18
+ #{setup_test_app}
19
+ Capybara::Screenshot.register_filename_prefix_formatter(:minitest) do |test_case|
20
+ test_name = test_case.respond_to?(:name) ? test_case.name : test_case.__name__
21
+ raise "expected fault" unless test_name.include? 'test_failure'
22
+ 'my_screenshot'
23
+ end
24
+
25
+ #{code}
26
+ RUBY
27
+
28
+ cmd = 'bundle exec ruby test_failure.rb'
29
+ run_simple_with_retry cmd, false
30
+ expect(output_from(cmd)).to include %q{Unable to find link or button "you'll never find me"}
31
+ end
32
+
33
+ it 'saves a screenshot on failure' do
34
+ run_failing_case <<-RUBY
35
+ module ActionDispatch
36
+ class IntegrationTest < Minitest::Unit::TestCase; end
37
+ end
38
+
39
+ class TestFailure < ActionDispatch::IntegrationTest
40
+ include Capybara::DSL
41
+
42
+ def test_failure
43
+ visit '/'
44
+ assert(page.body.include?('This is the root page'))
45
+ click_on "you'll never find me"
46
+ end
47
+ end
48
+ RUBY
49
+ check_file_content 'tmp/my_screenshot.html', 'This is the root page', true
50
+ end
51
+
52
+ it "does not save a screenshot for tests that don't inherit from ActionDispatch::IntegrationTest" do
53
+ run_failing_case <<-RUBY
54
+ class TestFailure < MiniTest::Unit::TestCase
55
+ include Capybara::DSL
56
+
57
+ def test_failure
58
+ visit '/'
59
+ assert(page.body.include?('This is the root page'))
60
+ click_on "you'll never find me"
61
+ end
62
+ end
63
+ RUBY
64
+ check_file_presence(%w{tmp/my_screenshot.html}, false)
65
+ end
66
+
67
+ it 'saves a screenshot for the correct session for failures using_session' do
68
+ run_failing_case <<-RUBY
69
+ module ActionDispatch
70
+ class IntegrationTest < Minitest::Unit::TestCase; end
71
+ end
72
+
73
+ class TestFailure < ActionDispatch::IntegrationTest
74
+ include Capybara::DSL
75
+
76
+ def test_failure
77
+ visit '/'
78
+ assert(page.body.include?('This is the root page'))
79
+ using_session :different_session do
80
+ visit '/different_page'
81
+ assert(page.body.include?('This is a different page'))
82
+ click_on "you'll never find me"
83
+ end
84
+ end
85
+ end
86
+ RUBY
87
+ check_file_content 'tmp/my_screenshot.html', 'This is a different page', true
88
+ end
89
+
90
+ it 'prunes screenshots on failure' do
91
+ create_screenshot_for_pruning
92
+ configure_prune_strategy :last_run
93
+ run_failing_case <<-RUBY
94
+ module ActionDispatch
95
+ class IntegrationTest < Minitest::Unit::TestCase; end
96
+ end
97
+
98
+ class TestFailure < ActionDispatch::IntegrationTest
99
+ include Capybara::DSL
100
+
101
+ def test_failure
102
+ visit '/'
103
+ assert(page.body.include?('This is the root page'))
104
+ click_on "you'll never find me"
105
+ end
106
+ end
107
+ RUBY
108
+ assert_screenshot_pruned
109
+ end
110
+ end
@@ -0,0 +1,81 @@
1
+ require "spec_helper"
2
+
3
+ describe "Using Capybara::Screenshot with Test::Unit" do
4
+ include CommonSetup
5
+
6
+ before do
7
+ clean_current_dir
8
+ end
9
+
10
+ def run_failing_case(code, integration_path = '.')
11
+ write_file("#{integration_path}/test_failure.rb", <<-RUBY)
12
+ #{ensure_load_paths_valid}
13
+ require 'test/unit'
14
+ require 'capybara'
15
+ require 'capybara/rspec'
16
+ require 'capybara-screenshot'
17
+ require 'capybara-screenshot/testunit'
18
+
19
+ #{setup_test_app}
20
+ Capybara::Screenshot.register_filename_prefix_formatter(:testunit) do | fault |
21
+ raise "expected fault" unless fault.exception.message.include? %q{Unable to find link or button "you'll never find me"}
22
+ 'my_screenshot'
23
+ end
24
+
25
+ class TestFailure < Test::Unit::TestCase
26
+ include Capybara::DSL
27
+
28
+ def test_failure
29
+ #{code}
30
+ end
31
+ end
32
+ RUBY
33
+
34
+ cmd = "bundle exec ruby #{integration_path}/test_failure.rb"
35
+ run_simple_with_retry cmd, false
36
+ expect(output_from(cmd)).to include %q{Unable to find link or button "you'll never find me"}
37
+ end
38
+
39
+ it "saves a screenshot on failure for any test in path 'test/integration'" do
40
+ run_failing_case <<-RUBY, 'test/integration'
41
+ visit '/'
42
+ assert(page.body.include?('This is the root page'))
43
+ click_on "you'll never find me"
44
+ RUBY
45
+ check_file_content 'tmp/my_screenshot.html', 'This is the root page', true
46
+ end
47
+
48
+ it "does not generate a screenshot for tests that are not in 'test/integration'" do
49
+ run_failing_case <<-RUBY, 'test/something-else'
50
+ visit '/'
51
+ assert(page.body.include?('This is the root page'))
52
+ click_on "you'll never find me"
53
+ RUBY
54
+
55
+ check_file_presence(%w{tmp/my_screenshot.html}, false)
56
+ end
57
+
58
+ it 'saves a screenshot for the correct session for failures using_session' do
59
+ run_failing_case <<-RUBY, 'test/integration'
60
+ visit '/'
61
+ assert(page.body.include?('This is the root page'))
62
+ using_session :different_session do
63
+ visit '/different_page'
64
+ assert(page.body.include?('This is a different page'))
65
+ click_on "you'll never find me"
66
+ end
67
+ RUBY
68
+ check_file_content 'tmp/my_screenshot.html', 'This is a different page', true
69
+ end
70
+
71
+ it 'prunes screenshots on failure' do
72
+ create_screenshot_for_pruning
73
+ configure_prune_strategy :last_run
74
+ run_failing_case <<-RUBY, 'test/integration'
75
+ visit '/'
76
+ assert(page.body.include?('This is the root page'))
77
+ click_on "you'll never find me"
78
+ RUBY
79
+ assert_screenshot_pruned
80
+ end
81
+ end
@@ -0,0 +1,159 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capybara::Screenshot::RSpec do
4
+ describe "used with RSpec" do
5
+ include CommonSetup
6
+
7
+ before do
8
+ clean_current_dir
9
+ end
10
+
11
+ def run_failing_case(code, error_message, format=nil)
12
+ run_case code, format: format
13
+
14
+ cmd = cmd_with_format(format)
15
+ if error_message.kind_of?(Regexp)
16
+ expect(output_from(cmd)).to match(error_message)
17
+ else
18
+ expect(output_from(cmd)).to include(error_message)
19
+ end
20
+ end
21
+
22
+ def run_case(code, options = {})
23
+ write_file('spec/test_failure.rb', <<-RUBY)
24
+ #{ensure_load_paths_valid}
25
+ require 'rspec'
26
+ require 'capybara'
27
+ require 'capybara/rspec'
28
+ require 'capybara-screenshot'
29
+ require 'capybara-screenshot/rspec'
30
+
31
+ #{setup_test_app}
32
+ #{code}
33
+ RUBY
34
+
35
+ cmd = cmd_with_format(options[:format])
36
+ run_simple_with_retry cmd, false
37
+
38
+ expect(output_from(cmd)).to include('0 failures') if options[:assert_all_passed]
39
+ end
40
+
41
+ def cmd_with_format(format)
42
+ "bundle exec rspec #{"--format #{format} " if format}spec/test_failure.rb"
43
+ end
44
+
45
+ it 'saves a screenshot on failure' do
46
+ run_failing_case <<-RUBY, %q{Unable to find link or button "you'll never find me"}
47
+ feature 'screenshot with failure' do
48
+ scenario 'click on a missing link' do
49
+ visit '/'
50
+ expect(page.body).to include('This is the root page')
51
+ click_on "you'll never find me"
52
+ end
53
+ end
54
+ RUBY
55
+ check_file_content('tmp/screenshot.html', 'This is the root page', true)
56
+ end
57
+
58
+ formatters = {
59
+ progress: 'HTML screenshot:',
60
+ documentation: 'HTML screenshot:',
61
+ html: %r{<a href="file://\./tmp/screenshot\.html"[^>]*>HTML page</a>}
62
+ }
63
+
64
+ # Textmate formatter is only included in RSpec 2
65
+ if RSpec::Core::Version::STRING.to_i == 2
66
+ formatters[:textmate] = %r{TextMate\.system\(.*open file://\./tmp/screenshot.html}
67
+ end
68
+
69
+ formatters.each do |formatter, error_message|
70
+ it "uses the associated #{formatter} formatter" do
71
+ run_failing_case <<-RUBY, error_message, formatter
72
+ feature 'screenshot with failure' do
73
+ scenario 'click on a missing link' do
74
+ visit '/'
75
+ click_on "you'll never find me"
76
+ end
77
+ end
78
+ RUBY
79
+ check_file_content('tmp/screenshot.html', 'This is the root page', true)
80
+ end
81
+ end
82
+
83
+ it "does not save a screenshot for tests that don't use Capybara" do
84
+ run_failing_case <<-RUBY, %q{expected: false}
85
+ describe 'failing test' do
86
+ it 'fails intentionally' do
87
+ expect(true).to eql(false)
88
+ end
89
+ end
90
+ RUBY
91
+ check_file_presence(%w{tmp/screenshot.html}, false)
92
+ end
93
+
94
+ it 'saves a screenshot for the correct session for failures using_session' do
95
+ run_failing_case <<-RUBY, %q{Unable to find link or button "you'll never find me"}
96
+ feature 'screenshot with failure' do
97
+ scenario 'click on a missing link' do
98
+ visit '/'
99
+ expect(page.body).to include('This is the root page')
100
+ using_session :different_session do
101
+ visit '/different_page'
102
+ expect(page.body).to include('This is a different page')
103
+ click_on "you'll never find me"
104
+ end
105
+ end
106
+ end
107
+ RUBY
108
+ check_file_content('tmp/screenshot.html', 'This is a different page', true)
109
+ end
110
+
111
+ context 'pruning' do
112
+ before do
113
+ create_screenshot_for_pruning
114
+ configure_prune_strategy :last_run
115
+ end
116
+
117
+ it 'on failure it prunes previous screenshots when strategy is set' do
118
+ run_failing_case <<-RUBY, 'HTML screenshot:', :progress
119
+ feature 'screenshot with failure' do
120
+ scenario 'click on a missing link' do
121
+ visit '/'
122
+ click_on "you'll never find me"
123
+ end
124
+ end
125
+ RUBY
126
+ assert_screenshot_pruned
127
+ end
128
+
129
+ it 'on success it never prunes' do
130
+ run_case <<-CUCUMBER, assert_all_passed: true
131
+ feature 'screenshot without failure' do
132
+ scenario 'click on a link' do
133
+ visit '/'
134
+ end
135
+ end
136
+ CUCUMBER
137
+ assert_screenshot_not_pruned
138
+ end
139
+ end
140
+
141
+ context 'no pruning by default' do
142
+ before do
143
+ create_screenshot_for_pruning
144
+ end
145
+
146
+ it 'on failure it leaves existing screenshots' do
147
+ run_failing_case <<-RUBY, 'HTML screenshot:', :progress
148
+ feature 'screenshot with failure' do
149
+ scenario 'click on a missing link' do
150
+ visit '/'
151
+ click_on "you'll never find me"
152
+ end
153
+ end
154
+ RUBY
155
+ assert_screenshot_not_pruned
156
+ end
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,29 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ $: << '../lib'
9
+ require 'rspec'
10
+ require 'capybara-screenshot'
11
+ require 'capybara-screenshot/rspec'
12
+ require 'timecop'
13
+ require 'aruba/api'
14
+ require 'aruba/jruby'
15
+
16
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
17
+
18
+ RSpec.configure do |config|
19
+ if RSpec::Core::Version::STRING.to_i == 2
20
+ config.treat_symbols_as_metadata_keys_with_true_values = true
21
+ end
22
+ config.run_all_when_everything_filtered = true
23
+ config.filter_run :focus
24
+ config.before do
25
+ @aruba_timeout_seconds = 60
26
+ end if RUBY_PLATFORM == 'java'
27
+ end
28
+
29
+ Capybara.app = lambda { |env| [200, {}, ["OK"]] }
@@ -0,0 +1,64 @@
1
+ require "spec_helper"
2
+
3
+ describe "Using Capybara::Screenshot with Spinach" do
4
+ include CommonSetup
5
+
6
+ before do
7
+ clean_current_dir
8
+ end
9
+
10
+ def run_failing_case(failure_message, code)
11
+ write_file('steps/failure.rb', <<-RUBY)
12
+ #{ensure_load_paths_valid}
13
+ require 'spinach/support/spinach_failure.rb'
14
+ #{setup_test_app}
15
+ RUBY
16
+
17
+ write_file('spinach.feature', code)
18
+ cmd = 'bundle exec spinach -f .'
19
+ run_simple_with_retry cmd, false
20
+ expect(output_from(cmd)).to match failure_message
21
+ end
22
+
23
+ it "saves a screenshot on failure" do
24
+ run_failing_case(%q{Unable to find link or button "you'll never find me"}, <<-GHERKIN)
25
+ Feature: Failure
26
+ Scenario: Failure
27
+ Given I visit "/"
28
+ And I click on a missing link
29
+ GHERKIN
30
+ check_file_content('tmp/my_screenshot.html', 'This is the root page', true)
31
+ end
32
+
33
+ it "saves a screenshot on an error" do
34
+ run_failing_case(%q{you can't handle me}, <<-GHERKIN)
35
+ Feature: Failure
36
+ Scenario: Failure
37
+ Given I visit "/"
38
+ And I trigger an unhandled exception
39
+ GHERKIN
40
+ check_file_content('tmp/my_screenshot.html', 'This is the root page', true)
41
+ end
42
+
43
+ it "saves a screenshot for the correct session for failures using_session" do
44
+ run_failing_case(%q{Unable to find link or button "you'll never find me"}, <<-GHERKIN)
45
+ Feature: Failure
46
+ Scenario: Failure in different session
47
+ Given I visit "/"
48
+ And I click on a missing link on a different page in a different session
49
+ GHERKIN
50
+ check_file_content('tmp/my_screenshot.html', 'This is a different page', true)
51
+ end
52
+
53
+ it 'on failure it prunes previous screenshots when strategy is set' do
54
+ create_screenshot_for_pruning
55
+ configure_prune_strategy :last_run
56
+ run_failing_case(%q{Unable to find link or button "you'll never find me"}, <<-GHERKIN)
57
+ Feature: Failure
58
+ Scenario: Failure
59
+ Given I visit "/"
60
+ And I click on a missing link
61
+ GHERKIN
62
+ assert_screenshot_pruned
63
+ end
64
+ end