rcarvalho-capybara 0.4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. data/History.txt +202 -0
  2. data/README.rdoc +540 -0
  3. data/lib/capybara.rb +231 -0
  4. data/lib/capybara/cucumber.rb +32 -0
  5. data/lib/capybara/driver/base.rb +60 -0
  6. data/lib/capybara/driver/celerity_driver.rb +164 -0
  7. data/lib/capybara/driver/culerity_driver.rb +26 -0
  8. data/lib/capybara/driver/node.rb +78 -0
  9. data/lib/capybara/driver/rack_test_driver.rb +303 -0
  10. data/lib/capybara/driver/selenium_driver.rb +165 -0
  11. data/lib/capybara/dsl.rb +109 -0
  12. data/lib/capybara/node/actions.rb +160 -0
  13. data/lib/capybara/node/base.rb +47 -0
  14. data/lib/capybara/node/document.rb +17 -0
  15. data/lib/capybara/node/element.rb +182 -0
  16. data/lib/capybara/node/finders.rb +201 -0
  17. data/lib/capybara/node/matchers.rb +391 -0
  18. data/lib/capybara/node/simple.rb +116 -0
  19. data/lib/capybara/rails.rb +17 -0
  20. data/lib/capybara/rspec.rb +18 -0
  21. data/lib/capybara/selector.rb +70 -0
  22. data/lib/capybara/server.rb +90 -0
  23. data/lib/capybara/session.rb +281 -0
  24. data/lib/capybara/spec/driver.rb +243 -0
  25. data/lib/capybara/spec/fixtures/capybara.jpg +0 -0
  26. data/lib/capybara/spec/fixtures/test_file.txt +1 -0
  27. data/lib/capybara/spec/public/jquery-ui.js +35 -0
  28. data/lib/capybara/spec/public/jquery.js +19 -0
  29. data/lib/capybara/spec/public/test.js +33 -0
  30. data/lib/capybara/spec/session.rb +110 -0
  31. data/lib/capybara/spec/session/all_spec.rb +78 -0
  32. data/lib/capybara/spec/session/attach_file_spec.rb +70 -0
  33. data/lib/capybara/spec/session/check_spec.rb +65 -0
  34. data/lib/capybara/spec/session/choose_spec.rb +26 -0
  35. data/lib/capybara/spec/session/click_button_spec.rb +252 -0
  36. data/lib/capybara/spec/session/click_link_or_button_spec.rb +36 -0
  37. data/lib/capybara/spec/session/click_link_spec.rb +113 -0
  38. data/lib/capybara/spec/session/current_url_spec.rb +15 -0
  39. data/lib/capybara/spec/session/fill_in_spec.rb +119 -0
  40. data/lib/capybara/spec/session/find_button_spec.rb +18 -0
  41. data/lib/capybara/spec/session/find_by_id_spec.rb +18 -0
  42. data/lib/capybara/spec/session/find_field_spec.rb +26 -0
  43. data/lib/capybara/spec/session/find_link_spec.rb +19 -0
  44. data/lib/capybara/spec/session/find_spec.rb +121 -0
  45. data/lib/capybara/spec/session/first_spec.rb +72 -0
  46. data/lib/capybara/spec/session/has_button_spec.rb +32 -0
  47. data/lib/capybara/spec/session/has_content_spec.rb +106 -0
  48. data/lib/capybara/spec/session/has_css_spec.rb +213 -0
  49. data/lib/capybara/spec/session/has_field_spec.rb +156 -0
  50. data/lib/capybara/spec/session/has_link_spec.rb +37 -0
  51. data/lib/capybara/spec/session/has_select_spec.rb +129 -0
  52. data/lib/capybara/spec/session/has_selector_spec.rb +129 -0
  53. data/lib/capybara/spec/session/has_table_spec.rb +96 -0
  54. data/lib/capybara/spec/session/has_xpath_spec.rb +123 -0
  55. data/lib/capybara/spec/session/headers.rb +19 -0
  56. data/lib/capybara/spec/session/javascript.rb +223 -0
  57. data/lib/capybara/spec/session/response_code.rb +19 -0
  58. data/lib/capybara/spec/session/select_spec.rb +105 -0
  59. data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
  60. data/lib/capybara/spec/session/unselect_spec.rb +61 -0
  61. data/lib/capybara/spec/session/within_spec.rb +160 -0
  62. data/lib/capybara/spec/test_app.rb +117 -0
  63. data/lib/capybara/spec/views/buttons.erb +4 -0
  64. data/lib/capybara/spec/views/fieldsets.erb +29 -0
  65. data/lib/capybara/spec/views/form.erb +348 -0
  66. data/lib/capybara/spec/views/frame_one.erb +8 -0
  67. data/lib/capybara/spec/views/frame_two.erb +8 -0
  68. data/lib/capybara/spec/views/popup_one.erb +8 -0
  69. data/lib/capybara/spec/views/popup_two.erb +8 -0
  70. data/lib/capybara/spec/views/postback.erb +13 -0
  71. data/lib/capybara/spec/views/tables.erb +122 -0
  72. data/lib/capybara/spec/views/with_html.erb +69 -0
  73. data/lib/capybara/spec/views/with_js.erb +39 -0
  74. data/lib/capybara/spec/views/with_scope.erb +36 -0
  75. data/lib/capybara/spec/views/with_simple_html.erb +1 -0
  76. data/lib/capybara/spec/views/within_frames.erb +10 -0
  77. data/lib/capybara/spec/views/within_popups.erb +25 -0
  78. data/lib/capybara/util/save_and_open_page.rb +40 -0
  79. data/lib/capybara/util/timeout.rb +27 -0
  80. data/lib/capybara/version.rb +3 -0
  81. data/spec/basic_node_spec.rb +77 -0
  82. data/spec/capybara_spec.rb +46 -0
  83. data/spec/driver/celerity_driver_spec.rb +13 -0
  84. data/spec/driver/culerity_driver_spec.rb +14 -0
  85. data/spec/driver/rack_test_driver_spec.rb +84 -0
  86. data/spec/driver/remote_culerity_driver_spec.rb +22 -0
  87. data/spec/driver/remote_selenium_driver_spec.rb +16 -0
  88. data/spec/driver/selenium_driver_spec.rb +14 -0
  89. data/spec/dsl_spec.rb +157 -0
  90. data/spec/rspec_spec.rb +47 -0
  91. data/spec/save_and_open_page_spec.rb +159 -0
  92. data/spec/server_spec.rb +85 -0
  93. data/spec/session/celerity_session_spec.rb +24 -0
  94. data/spec/session/culerity_session_spec.rb +26 -0
  95. data/spec/session/rack_test_session_spec.rb +44 -0
  96. data/spec/session/selenium_session_spec.rb +26 -0
  97. data/spec/spec_helper.rb +40 -0
  98. data/spec/string_spec.rb +77 -0
  99. data/spec/timeout_spec.rb +28 -0
  100. metadata +343 -0
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capybara do
4
+
5
+ describe 'default_wait_time' do
6
+ after do
7
+ Capybara.default_wait_time = @previous_default_time
8
+ end
9
+
10
+ it "should be changeable" do
11
+ @previous_default_time = Capybara.default_wait_time
12
+ Capybara.default_wait_time = 5
13
+ Capybara.default_wait_time.should == 5
14
+ end
15
+ end
16
+
17
+ describe '.register_driver' do
18
+ it "should add a new driver" do
19
+ Capybara.register_driver :schmoo do |app|
20
+ Capybara::Driver::RackTest.new(app)
21
+ end
22
+ session = Capybara::Session.new(:schmoo, TestApp)
23
+ session.visit('/')
24
+ session.body.should include("Hello world!")
25
+ end
26
+ end
27
+
28
+ describe ".server" do
29
+ after do
30
+ Capybara.server {|app, port| Capybara.run_default_server(app, port)}
31
+ end
32
+
33
+ it "should default to a proc that calls run_default_server" do
34
+ mock_app = mock('app')
35
+ Capybara.should_receive(:run_default_server).with(mock_app, 8000)
36
+ Capybara.server.call(mock_app, 8000)
37
+ end
38
+
39
+ it "should return a custom server proc" do
40
+ server = lambda {|app, port|}
41
+ Capybara.server(&server)
42
+ Capybara.server.should == server
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capybara::Driver::Celerity, :jruby => :platform do
4
+ before(:all) do
5
+ @driver = TestSessions::Celerity.driver
6
+ end
7
+
8
+ it_should_behave_like "driver"
9
+ it_should_behave_like "driver with javascript support"
10
+ it_should_behave_like "driver with header support"
11
+ it_should_behave_like "driver with status code support"
12
+ it_should_behave_like "driver with cookies support"
13
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capybara::Driver::Culerity, :jruby => :installed do
4
+
5
+ before(:all) do
6
+ @driver = TestSessions::Culerity.driver
7
+ end
8
+
9
+ it_should_behave_like "driver"
10
+ it_should_behave_like "driver with javascript support"
11
+ it_should_behave_like "driver with header support"
12
+ it_should_behave_like "driver with status code support"
13
+ it_should_behave_like "driver with cookies support"
14
+ end
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'stringio'
4
+
5
+ def capture(*streams)
6
+ streams.map! { |stream| stream.to_s }
7
+ begin
8
+ result = StringIO.new
9
+ streams.each { |stream| eval "$#{stream} = result" }
10
+ yield
11
+ ensure
12
+ streams.each { |stream| eval("$#{stream} = #{stream.upcase}") }
13
+ end
14
+ result.string
15
+ end
16
+
17
+ describe Capybara::Driver::RackTest do
18
+ before do
19
+ @driver = TestSessions::RackTest.driver
20
+ end
21
+
22
+ it "should throw an error when no rack app is given" do
23
+ running do
24
+ Capybara::Driver::RackTest.new(nil)
25
+ end.should raise_error(ArgumentError)
26
+ end
27
+
28
+ if '1.9'.respond_to?(:encode)
29
+ describe "with non-binary parameters" do
30
+
31
+ it "should convert attribute values to binary" do
32
+ output = capture(:stderr) {
33
+ @driver.visit('/mypage', :param => 'µ')
34
+ }.should_not =~ %r{warning: regexp match /.../n against to UTF-8 string}
35
+ end
36
+
37
+ it "should convert attribute with Array to binary" do
38
+ output = capture(:stderr) {
39
+ @driver.visit('/mypage', :param => ['µ'])
40
+ }.should_not =~ %r{warning: regexp match /.../n against to UTF-8 string}
41
+ end
42
+
43
+ it "should convert path to binary" do
44
+ output = capture(:stderr) {
45
+ @driver.visit('/mypage'.encode('utf-8'))
46
+ }.should_not =~ %r{warning: regexp match /.../n against to UTF-8 string}
47
+ end
48
+ end
49
+ end
50
+
51
+ it_should_behave_like "driver"
52
+ it_should_behave_like "driver with header support"
53
+ it_should_behave_like "driver with status code support"
54
+ it_should_behave_like "driver with cookies support"
55
+ it_should_behave_like "driver with infinite redirect detection"
56
+
57
+ describe '#reset!' do
58
+ it { @driver.visit('/foo'); lambda { @driver.reset! }.should change(@driver, :current_url).to('') }
59
+
60
+ it 'should reset headers' do
61
+ @driver.header('FOO', 'BAR')
62
+ @driver.visit('/get_header')
63
+ @driver.body.should include('BAR')
64
+
65
+ @driver.reset!
66
+ @driver.visit('/get_header')
67
+ @driver.body.should_not include('BAR')
68
+ end
69
+
70
+ it 'should reset response' do
71
+ @driver.visit('/foo')
72
+ lambda { @driver.response }.should_not raise_error
73
+ @driver.reset!
74
+ lambda { @driver.response }.should raise_error
75
+ end
76
+
77
+ it 'should request response' do
78
+ @driver.visit('/foo')
79
+ lambda { @driver.request }.should_not raise_error
80
+ @driver.reset!
81
+ lambda { @driver.request }.should raise_error
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capybara::Driver::Culerity, :jruby => :installed do
4
+ before(:all) do
5
+ Capybara.app_host = "http://capybara-testapp.heroku.com"
6
+ @driver = TestSessions::Culerity.driver
7
+ end
8
+
9
+ after(:all) do
10
+ Capybara.app_host = nil
11
+ end
12
+
13
+ it "should navigate to a fully qualified remote page" do
14
+ @driver.visit('http://capybara-testapp.heroku.com/foo')
15
+ @driver.body.should include('Another World')
16
+ end
17
+
18
+ it_should_behave_like "driver"
19
+ it_should_behave_like "driver with javascript support"
20
+ it_should_behave_like "driver with header support"
21
+ it_should_behave_like "driver with status code support"
22
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capybara::Driver::Selenium do
4
+ before do
5
+ #Capybara.app_host = "http://capybara-testapp.heroku.com"
6
+ @driver = TestSessions::Selenium.driver
7
+ end
8
+
9
+ after do
10
+ Capybara.app_host = nil
11
+ end
12
+
13
+ it_should_behave_like "driver"
14
+ it_should_behave_like "driver with javascript support"
15
+ it_should_behave_like "driver without status code support"
16
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capybara::Driver::Selenium do
4
+ before do
5
+ @driver = TestSessions::Selenium.driver
6
+ end
7
+
8
+ it_should_behave_like "driver"
9
+ it_should_behave_like "driver with javascript support"
10
+ it_should_behave_like "driver with frame support"
11
+ it_should_behave_like "driver with support for window switching"
12
+ it_should_behave_like "driver without status code support"
13
+ it_should_behave_like "driver with cookies support"
14
+ end
@@ -0,0 +1,157 @@
1
+ require 'spec_helper'
2
+
3
+ require 'capybara/dsl'
4
+
5
+ describe Capybara do
6
+
7
+ before do
8
+ Capybara.app = TestApp
9
+ end
10
+
11
+ after do
12
+ Capybara.default_driver = nil
13
+ Capybara.use_default_driver
14
+ end
15
+
16
+ describe '#default_driver' do
17
+ it "should default to rack_test" do
18
+ Capybara.default_driver.should == :rack_test
19
+ end
20
+
21
+ it "should be changeable" do
22
+ Capybara.default_driver = :culerity
23
+ Capybara.default_driver.should == :culerity
24
+ end
25
+ end
26
+
27
+ describe '#current_driver' do
28
+ it "should default to the default driver" do
29
+ Capybara.current_driver.should == :rack_test
30
+ Capybara.default_driver = :culerity
31
+ Capybara.current_driver.should == :culerity
32
+ end
33
+
34
+ it "should be changeable" do
35
+ Capybara.current_driver = :culerity
36
+ Capybara.current_driver.should == :culerity
37
+ end
38
+ end
39
+
40
+ describe '#javascript_driver' do
41
+ it "should default to selenium" do
42
+ Capybara.javascript_driver.should == :selenium
43
+ end
44
+
45
+ it "should be changeable" do
46
+ Capybara.javascript_driver = :culerity
47
+ Capybara.javascript_driver.should == :culerity
48
+ end
49
+ end
50
+
51
+ describe '#use_default_driver' do
52
+ it "should restore the default driver" do
53
+ Capybara.current_driver = :culerity
54
+ Capybara.use_default_driver
55
+ Capybara.current_driver.should == :rack_test
56
+ end
57
+ end
58
+
59
+ describe '#using_driver' do
60
+ before do
61
+ Capybara.current_driver.should_not == :selenium
62
+ end
63
+
64
+ it 'should set the driver using Capybara.current_driver=' do
65
+ driver = nil
66
+ Capybara.using_driver(:selenium) { driver = Capybara.current_driver }
67
+ driver.should == :selenium
68
+ end
69
+
70
+ it 'should reset the driver using Capybara.use_default_driver, even if an exception occurs' do
71
+ begin
72
+ Capybara.using_driver(:selenium) { raise "ohnoes!" }
73
+ rescue Exception
74
+ end
75
+ Capybara.current_driver.should == Capybara.default_driver
76
+ end
77
+
78
+ it 'should yield the passed block' do
79
+ called = false
80
+ Capybara.using_driver(:selenium) { called = true }
81
+ called.should == true
82
+ end
83
+ end
84
+
85
+ describe '#app' do
86
+ it "should be changeable" do
87
+ Capybara.app = "foobar"
88
+ Capybara.app.should == 'foobar'
89
+ end
90
+ end
91
+
92
+ describe '#current_session' do
93
+ it "should choose a session object of the current driver type" do
94
+ Capybara.current_session.should be_a(Capybara::Session)
95
+ end
96
+
97
+ it "should use #app as the application" do
98
+ Capybara.app = proc {}
99
+ Capybara.current_session.app.should == Capybara.app
100
+ end
101
+
102
+ it "should change with the current driver" do
103
+ Capybara.current_session.mode.should == :rack_test
104
+ Capybara.current_driver = :selenium
105
+ Capybara.current_session.mode.should == :selenium
106
+ end
107
+
108
+ it "should be persistent even across driver changes" do
109
+ object_id = Capybara.current_session.object_id
110
+ Capybara.current_session.object_id.should == object_id
111
+ Capybara.current_driver = :selenium
112
+ Capybara.current_session.mode.should == :selenium
113
+ Capybara.current_session.object_id.should_not == object_id
114
+
115
+ Capybara.current_driver = :rack_test
116
+ Capybara.current_session.object_id.should == object_id
117
+ end
118
+
119
+ it "should change when changing application" do
120
+ object_id = Capybara.current_session.object_id
121
+ Capybara.current_session.object_id.should == object_id
122
+ Capybara.app = proc {}
123
+ Capybara.current_session.object_id.should_not == object_id
124
+ Capybara.current_session.app.should == Capybara.app
125
+ end
126
+ end
127
+
128
+ describe 'the DSL' do
129
+ before do
130
+ @session = Capybara
131
+ end
132
+
133
+ it_should_behave_like "session"
134
+ it_should_behave_like "session without javascript support"
135
+
136
+ it "should be possible to include it in another class" do
137
+ klass = Class.new do
138
+ include Capybara
139
+ end
140
+ foo = klass.new
141
+ foo.visit('/with_html')
142
+ foo.click_link('ullamco')
143
+ foo.body.should include('Another World')
144
+ end
145
+
146
+ it "should provide a 'page' shortcut for more expressive tests" do
147
+ klass = Class.new do
148
+ include Capybara
149
+ end
150
+ foo = klass.new
151
+ foo.page.visit('/with_html')
152
+ foo.page.click_link('ullamco')
153
+ foo.page.body.should include('Another World')
154
+ end
155
+ end
156
+
157
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ require 'capybara/rspec'
3
+
4
+ Capybara.app = TestApp
5
+
6
+ describe 'capybara/rspec', :type => :acceptance do
7
+ it "should include Capybara in rpsec" do
8
+ visit('/foo')
9
+ page.body.should include('Another World')
10
+ end
11
+
12
+ context "resetting session" do
13
+ it "sets a cookie in one example..." do
14
+ visit('/set_cookie')
15
+ page.body.should include('Cookie set to test_cookie')
16
+ end
17
+
18
+ it "...then it is not availbable in the next" do
19
+ visit('/get_cookie')
20
+ page.body.should_not include('test_cookie')
21
+ end
22
+ end
23
+
24
+ context "setting the current driver" do
25
+ it "sets the current driver in one example..." do
26
+ Capybara.current_driver = :selenium
27
+ end
28
+
29
+ it "...then it has returned to the default in the next example" do
30
+ Capybara.current_driver.should == :rack_test
31
+ end
32
+ end
33
+
34
+ it "switches to the javascript driver when giving it as metadata", :js => true do
35
+ Capybara.current_driver.should == Capybara.javascript_driver
36
+ end
37
+
38
+ it "switches to the given driver when giving it as metadata", :driver => :culerity do
39
+ Capybara.current_driver.should == :culerity
40
+ end
41
+ end
42
+
43
+ describe 'capybara/rspec', :type => :other do
44
+ it "should not include Capybara" do
45
+ expect { visit('/') }.to raise_error(NoMethodError)
46
+ end
47
+ end
@@ -0,0 +1,159 @@
1
+ require 'spec_helper'
2
+
3
+ require 'capybara/util/save_and_open_page'
4
+ require 'launchy'
5
+ describe Capybara do
6
+ describe ".save_and_open_page" do
7
+ before do
8
+ @time = Time.new.strftime("%Y%m%d%H%M%S")
9
+
10
+ @temp_file = mock("FILE")
11
+ @temp_file.stub!(:write)
12
+ @temp_file.stub!(:close)
13
+
14
+ @html = <<-HTML
15
+ <html>
16
+ <head>
17
+ <script type="text/javascript" src="/javascripts/prototype.js?123"/>
18
+ </head>
19
+ <body>
20
+ <h1>test</h1>
21
+ <p>
22
+ Some images (note differing whitespace closing tag):
23
+ <img src="/images/image1.jpeg" />
24
+ <img src="/images/image2.jpeg"/>
25
+ </p>
26
+ <p>
27
+ Some more in a non-existent directory:
28
+ <img src="/img/image3.jpeg" />
29
+ <img src="/img/image4.jpeg"/>
30
+ </p>
31
+ <p>
32
+ <a href="/not-here/foo.html">
33
+ A link to a file in a non-existent directory.
34
+ </a>
35
+ </p>
36
+ </body>
37
+ <html>
38
+ HTML
39
+
40
+ Launchy::Browser.stub(:run)
41
+ end
42
+
43
+ def default_file_expectations
44
+ @name = "capybara-#{@time}.html"
45
+
46
+ @temp_file.stub!(:path).and_return(@name)
47
+
48
+ File.should_receive(:exist?).and_return true
49
+ File.should_receive(:new).and_return @temp_file
50
+ end
51
+
52
+ describe "defaults" do
53
+ before do
54
+ default_file_expectations
55
+ end
56
+
57
+ it "should create a new temporary file" do
58
+ @temp_file.should_receive(:write).with @html
59
+ Capybara.save_and_open_page @html
60
+ end
61
+
62
+ it "should open the file in the browser" do
63
+ Capybara.should_receive(:open_in_browser).with(@name)
64
+ Capybara.save_and_open_page @html
65
+ end
66
+ end
67
+
68
+ describe "custom output path" do
69
+ before do
70
+ @custom_path = File.join('tmp', 'capybara')
71
+ @custom_name = File.join(@custom_path, "capybara-#{@time}.html")
72
+
73
+ @temp_file.stub!(:path).and_return(@custom_name)
74
+
75
+ Capybara.should_receive(:save_and_open_page_path).at_least(:once).and_return(@custom_path)
76
+ end
77
+
78
+ it "should create a new temporary file in the custom path" do
79
+ File.should_receive(:directory?).and_return true
80
+ File.should_receive(:exist?).and_return true
81
+ File.should_receive(:new).and_return @temp_file
82
+
83
+ @temp_file.should_receive(:write).with @html
84
+ Capybara.save_and_open_page @html
85
+ end
86
+
87
+ it "should open the file - in the custom path - in the browser" do
88
+ Capybara.should_receive(:open_in_browser).with(@custom_name)
89
+ Capybara.save_and_open_page @html
90
+ end
91
+
92
+ it "should be possible to configure output path" do
93
+ Capybara.should respond_to(:save_and_open_page_path)
94
+ default_setting = Capybara.save_and_open_page_path
95
+ lambda {
96
+ Capybara.save_and_open_page_path = File.join('tmp', 'capybara')
97
+ Capybara.save_and_open_page_path.should == File.join('tmp', 'capybara')
98
+ }.should_not raise_error
99
+ Capybara.save_and_open_page_path = default_setting
100
+ end
101
+ end
102
+
103
+ describe "rewrite_css_and_image_references" do
104
+ before do
105
+ default_file_expectations
106
+ @asset_root_dir = "/path/to/rails/public"
107
+ end
108
+
109
+ def mock_asset_root_with(directories)
110
+ @asset_root = Pathname.new(@asset_root_dir)
111
+ Capybara.should_receive(:asset_root).and_return @asset_root
112
+
113
+ dir = mock('asset_root mock dir')
114
+ Dir.should_receive(:new).with(@asset_root).and_return dir
115
+
116
+ dirents = [ '.', '..', 'file.html' ] + directories
117
+ dir.should_receive(:entries).and_return dirents
118
+
119
+ directories_regexp = directories.join('|')
120
+ FileTest.should_receive(:directory?) \
121
+ .at_least(dirents.size - 2).times \
122
+ .and_return { |dir|
123
+ dir =~ %r!#{@asset_root_dir}/(#{directories_regexp})$!
124
+ }
125
+ end
126
+
127
+ def expected_html_for_asset_root_with(directories)
128
+ mock_asset_root_with(directories)
129
+
130
+ expected_html = @html.clone
131
+ if not directories.empty?
132
+ directories_regexp = directories.join('|')
133
+ expected_html.gsub!(/"(\/(#{directories_regexp})\/)/,
134
+ '"%s\1' % @asset_root_dir)
135
+ end
136
+
137
+ return expected_html
138
+ end
139
+
140
+ def test_with_directories(directories)
141
+ @temp_file.should_receive(:write) \
142
+ .with expected_html_for_asset_root_with(directories)
143
+ Capybara.save_and_open_page @html
144
+ end
145
+
146
+ context "asset_root contains some directories" do
147
+ it "should rewrite relative paths to absolute local paths" do
148
+ test_with_directories([ 'javascripts', 'images' ])
149
+ end
150
+ end
151
+
152
+ context "asset_root path contains no directories" do
153
+ it "should not rewrite any relative paths" do
154
+ test_with_directories([ ])
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end