capybara-restore_state 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 48500d9a5708410946422258c045c6b915e3370f
4
+ data.tar.gz: 5f769fcceb84727634c728f283327335548ded23
5
+ SHA512:
6
+ metadata.gz: 018808ec55c0e68389e9fa69bd6430d70dddabf77144345c2a819b44cd2ba9edadc6f116014864866e8a25e8097bb3d75ba29436456510a18b1f0bd335424754
7
+ data.tar.gz: 700925e61bf577fda2348df428393f336c4deead5d54a824b2064d7e5fd27150e55a1f902929a9302e098c7d6be74c60166da9f8c405075c5776c64ce5432b92
@@ -0,0 +1,3 @@
1
+ === 1.0.0 (2016-05-25)
2
+
3
+ * Initial Public Release
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2016 Jeremy Evans
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ = capybara-restore_state
2
+
3
+ capybara-restore_state offers the ability to execute a block where the
4
+ initial capybara state on entering the block is returned after the block
5
+ is executed. This makes it possible to test things like clicking on the
6
+ same button twice.
7
+
8
+ This only works for the rack-test driver, other drivers can use the back
9
+ buttons provided by the browser.
10
+
11
+ = Installation
12
+
13
+ gem install capybara-restore_state
14
+
15
+ = Source Code
16
+
17
+ Source code is available on GitHub at https://github.com/jeremyevans/capybara-restore_state
18
+
19
+ = Examples
20
+
21
+ require 'capybara'
22
+ require 'capybara/restore_state'
23
+
24
+ describe Capybara::RestoreState do
25
+ include Rack::Test::Methods
26
+ include Capybara::DSL
27
+ include Capybara::RestoreState
28
+
29
+ def app
30
+ MyRackApp
31
+ end
32
+
33
+ it "should allow restoring of state" do
34
+ # Assume Submit button takes you /a
35
+ visit '/'
36
+ page.current_path # => '/'
37
+
38
+ restore_state do
39
+ page.current_path # => '/'
40
+ click_button 'Submit'
41
+ page.current_path # => '/a'
42
+ end
43
+
44
+ page.current_path # => '/'
45
+ click_button 'Submit'
46
+ page.current_path # => '/a'
47
+ end
48
+ end
49
+
50
+ = License
51
+
52
+ MIT
53
+
54
+ = Author
55
+
56
+ Jeremy Evans <code@jeremyevans.net>
@@ -0,0 +1,46 @@
1
+ require "rake"
2
+ require "rake/clean"
3
+ require 'rake/testtask'
4
+
5
+ CLEAN.include ["capybara-restore_state-*.gem", "rdoc", "coverage"]
6
+
7
+ desc "Build enum_csv gem"
8
+ task :package=>[:clean] do |p|
9
+ sh %{#{FileUtils::RUBY} -S gem build capybara-restore_state.gemspec}
10
+ end
11
+
12
+ ### Specs
13
+
14
+ desc "Run specs"
15
+ task :default=>:spec
16
+
17
+ desc "Run specs"
18
+ task :spec do
19
+ sh "#{FileUtils::RUBY} spec/capybara-restore_state_spec.rb"
20
+ end
21
+ ### RDoc
22
+
23
+ RDOC_DEFAULT_OPTS = ["--quiet", "--line-numbers", "--inline-source", '--title', 'capybara-restore_state: Restore capybara state after block execution']
24
+
25
+ begin
26
+ gem 'hanna-nouveau'
27
+ RDOC_DEFAULT_OPTS.concat(['-f', 'hanna'])
28
+ rescue Gem::LoadError
29
+ end
30
+
31
+ rdoc_task_class = begin
32
+ require "rdoc/task"
33
+ RDoc::Task
34
+ rescue LoadError
35
+ require "rake/rdoctask"
36
+ Rake::RDocTask
37
+ end
38
+
39
+ RDOC_OPTS = RDOC_DEFAULT_OPTS + ['--main', 'README.rdoc']
40
+
41
+ rdoc_task_class.new do |rdoc|
42
+ rdoc.rdoc_dir = "rdoc"
43
+ rdoc.options += RDOC_OPTS
44
+ rdoc.rdoc_files.add %w"README.rdoc CHANGELOG MIT-LICENSE lib/**/*.rb"
45
+ end
46
+
@@ -0,0 +1,15 @@
1
+ require 'capybara'
2
+
3
+ module Capybara::RestoreState
4
+ # Yield to the block, restoring the capybara session state after block execution.
5
+ def restore_state
6
+ mock_session = page.driver.browser.instance_variable_get(:@_rack_mock_sessions)[:default]
7
+ last_response = mock_session.last_response
8
+ last_request = mock_session.last_request
9
+ yield
10
+ ensure
11
+ mock_session.instance_variable_set(:@last_response, last_response)
12
+ mock_session.instance_variable_set(:@last_request, last_request)
13
+ page.driver.browser.reset_cache!
14
+ end
15
+ end
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ gem 'minitest'
3
+ require 'minitest/spec'
4
+ require 'minitest/autorun'
5
+ require 'capybara'
6
+ require 'capybara/dsl'
7
+ require './lib/capybara/restore_state'
8
+
9
+ MyRackApp = lambda do |env|
10
+ s = "<html><body><form action='/a'>#{env['PATH_INFO']}<input type='submit' value='Submit' /></form></body></html>"
11
+ [200, {'Content-Length'=>s.length}, s]
12
+ end
13
+ Capybara.app = MyRackApp
14
+
15
+ describe Capybara::RestoreState do
16
+ include Rack::Test::Methods
17
+ include Capybara::DSL
18
+ include Capybara::RestoreState
19
+
20
+ def app
21
+ MyRackApp
22
+ end
23
+
24
+ it "should allow restoring of state" do
25
+ visit '/'
26
+ page.current_path.must_equal '/'
27
+ page.text.must_equal '/'
28
+
29
+ restore_state do
30
+ page.text.must_equal '/'
31
+ page.current_path.must_equal '/'
32
+ click_button 'Submit'
33
+ page.current_path.must_equal '/a'
34
+ page.text.must_equal '/a'
35
+ end
36
+
37
+ page.current_path.must_equal '/'
38
+ page.text.must_equal '/'
39
+ click_button 'Submit'
40
+ page.current_path.must_equal '/a'
41
+ page.text.must_equal '/a'
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-restore_state
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Evans
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack-test
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: capybara
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.0
41
+ description: |
42
+ capybara-restore_state offers the ability to execute a block where the
43
+ initial capybara state on entering the block is returned after the block
44
+ is executed. This makes it possible to test things like clicking on the
45
+ same button twice.
46
+ email: code@jeremyevans.net
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files:
50
+ - README.rdoc
51
+ - CHANGELOG
52
+ - MIT-LICENSE
53
+ files:
54
+ - CHANGELOG
55
+ - MIT-LICENSE
56
+ - README.rdoc
57
+ - Rakefile
58
+ - lib/capybara/restore_state.rb
59
+ - spec/capybara-restore_state_spec.rb
60
+ homepage: http://github.com/jeremyevans/capybara-restore_state
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options:
66
+ - "--quiet"
67
+ - "--line-numbers"
68
+ - "--inline-source"
69
+ - "--title"
70
+ - 'capybara-restore_state: Restore capybara state after block execution'
71
+ - "--main"
72
+ - README.rdoc
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.5.1
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Restore capybara state after block execution
91
+ test_files: []