fletcherm-culerity 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/.gitignore +6 -0
  2. data/CHANGES.md +7 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +102 -0
  5. data/Rakefile +47 -0
  6. data/VERSION.yml +5 -0
  7. data/culerity.gemspec +165 -0
  8. data/features/fixtures/jquery +4376 -0
  9. data/features/fixtures/sample_feature +14 -0
  10. data/features/installing_culerity.feature +36 -0
  11. data/features/running_cucumber_without_explicitly_running_external_services.feature +23 -0
  12. data/features/step_definitions/common_steps.rb +175 -0
  13. data/features/step_definitions/culerity_setup_steps.rb +7 -0
  14. data/features/step_definitions/jruby_steps.rb +11 -0
  15. data/features/step_definitions/rails_setup_steps.rb +36 -0
  16. data/features/support/common.rb +32 -0
  17. data/features/support/env.rb +24 -0
  18. data/features/support/matchers.rb +11 -0
  19. data/init.rb +1 -0
  20. data/lib/culerity.rb +44 -0
  21. data/lib/culerity/celerity_server.rb +81 -0
  22. data/lib/culerity/jruby_runner.rb +13 -0
  23. data/lib/culerity/remote_browser_proxy.rb +58 -0
  24. data/lib/culerity/remote_object_proxy.rb +76 -0
  25. data/rails/init.rb +1 -0
  26. data/rails_generators/culerity/culerity_generator.rb +28 -0
  27. data/rails_generators/culerity/templates/config/environments/culerity_continuousintegration.rb +28 -0
  28. data/rails_generators/culerity/templates/config/environments/culerity_development.rb +17 -0
  29. data/rails_generators/culerity/templates/features/step_definitions/culerity_steps.rb +109 -0
  30. data/rails_generators/culerity/templates/features/support/env.rb +9 -0
  31. data/rails_generators/culerity/templates/lib/tasks/culerity.rake +38 -0
  32. data/rails_generators/culerity/templates/public/javascripts/culerity.js +27 -0
  33. data/script/console +10 -0
  34. data/script/destroy +14 -0
  35. data/script/generate +14 -0
  36. data/spec/celerity_server_spec.rb +106 -0
  37. data/spec/culerity_spec.rb +33 -0
  38. data/spec/jruby_runner_spec.rb +12 -0
  39. data/spec/remote_browser_proxy_spec.rb +62 -0
  40. data/spec/remote_object_proxy_spec.rb +63 -0
  41. data/spec/spec_helper.rb +3 -0
  42. data/vendor/gems/celerity-0.7.6/HISTORY +111 -0
  43. data/vendor/gems/celerity-0.7.6/LICENSE +621 -0
  44. data/vendor/gems/celerity-0.7.6/README.rdoc +80 -0
  45. data/vendor/gems/celerity-0.7.6/Rakefile +11 -0
  46. data/vendor/gems/celerity-0.7.6/VERSION.yml +5 -0
  47. data/vendor/gems/celerity-0.7.6/celerity.gemspec +120 -0
  48. data/vendor/gems/celerity-0.7.6/lib/celerity.rb +77 -0
  49. data/vendor/gems/celerity-0.7.6/lib/celerity/browser.rb +893 -0
  50. data/vendor/gems/celerity-0.7.6/lib/celerity/clickable_element.rb +73 -0
  51. data/vendor/gems/celerity-0.7.6/lib/celerity/collections.rb +156 -0
  52. data/vendor/gems/celerity-0.7.6/lib/celerity/container.rb +767 -0
  53. data/vendor/gems/celerity-0.7.6/lib/celerity/default_viewer.rb +14 -0
  54. data/vendor/gems/celerity-0.7.6/lib/celerity/disabled_element.rb +40 -0
  55. data/vendor/gems/celerity-0.7.6/lib/celerity/element.rb +298 -0
  56. data/vendor/gems/celerity-0.7.6/lib/celerity/element_collection.rb +107 -0
  57. data/vendor/gems/celerity-0.7.6/lib/celerity/element_locator.rb +159 -0
  58. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/button.rb +54 -0
  59. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/file_field.rb +29 -0
  60. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/form.rb +33 -0
  61. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/frame.rb +86 -0
  62. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/image.rb +89 -0
  63. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/label.rb +16 -0
  64. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/link.rb +43 -0
  65. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/meta.rb +14 -0
  66. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/non_control_elements.rb +116 -0
  67. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/option.rb +38 -0
  68. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/radio_check.rb +114 -0
  69. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/select_list.rb +147 -0
  70. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/table.rb +153 -0
  71. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/table_cell.rb +36 -0
  72. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/table_elements.rb +42 -0
  73. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/table_row.rb +49 -0
  74. data/vendor/gems/celerity-0.7.6/lib/celerity/elements/text_field.rb +168 -0
  75. data/vendor/gems/celerity-0.7.6/lib/celerity/exception.rb +83 -0
  76. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit.rb +64 -0
  77. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/commons-codec-1.4.jar +0 -0
  78. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/commons-collections-3.2.1.jar +0 -0
  79. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/commons-httpclient-3.1.jar +0 -0
  80. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/commons-io-1.4.jar +0 -0
  81. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/commons-lang-2.4.jar +0 -0
  82. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/commons-logging-1.1.1.jar +0 -0
  83. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/cssparser-0.9.5.jar +0 -0
  84. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/htmlunit-2.7-SNAPSHOT.jar +0 -0
  85. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/htmlunit-core-js-2.7-SNAPSHOT.jar +0 -0
  86. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/nekohtml-1.9.14-20091130.152932-3.jar +0 -0
  87. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/sac-1.3.jar +0 -0
  88. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/serializer-2.7.1.jar +0 -0
  89. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/xalan-2.7.1.jar +0 -0
  90. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/xercesImpl-2.9.1.jar +0 -0
  91. data/vendor/gems/celerity-0.7.6/lib/celerity/htmlunit/xml-apis-1.3.04.jar +0 -0
  92. data/vendor/gems/celerity-0.7.6/lib/celerity/identifier.rb +28 -0
  93. data/vendor/gems/celerity-0.7.6/lib/celerity/ignoring_web_connection.rb +15 -0
  94. data/vendor/gems/celerity-0.7.6/lib/celerity/input_element.rb +25 -0
  95. data/vendor/gems/celerity-0.7.6/lib/celerity/javascript_debugger.rb +32 -0
  96. data/vendor/gems/celerity-0.7.6/lib/celerity/listener.rb +143 -0
  97. data/vendor/gems/celerity-0.7.6/lib/celerity/resources/no_viewer.png +0 -0
  98. data/vendor/gems/celerity-0.7.6/lib/celerity/short_inspect.rb +20 -0
  99. data/vendor/gems/celerity-0.7.6/lib/celerity/util.rb +126 -0
  100. data/vendor/gems/celerity-0.7.6/lib/celerity/version.rb +3 -0
  101. data/vendor/gems/celerity-0.7.6/lib/celerity/viewer_connection.rb +89 -0
  102. data/vendor/gems/celerity-0.7.6/lib/celerity/watir_compatibility.rb +70 -0
  103. data/vendor/gems/celerity-0.7.6/lib/celerity/xpath_support.rb +48 -0
  104. data/vendor/gems/celerity-0.7.6/tasks/benchmark.rake +4 -0
  105. data/vendor/gems/celerity-0.7.6/tasks/check.rake +24 -0
  106. data/vendor/gems/celerity-0.7.6/tasks/clean.rake +3 -0
  107. data/vendor/gems/celerity-0.7.6/tasks/fix.rake +25 -0
  108. data/vendor/gems/celerity-0.7.6/tasks/jar.rake +55 -0
  109. data/vendor/gems/celerity-0.7.6/tasks/jeweler.rake +26 -0
  110. data/vendor/gems/celerity-0.7.6/tasks/rdoc.rake +4 -0
  111. data/vendor/gems/celerity-0.7.6/tasks/snapshot.rake +22 -0
  112. data/vendor/gems/celerity-0.7.6/tasks/spec.rake +26 -0
  113. data/vendor/gems/celerity-0.7.6/tasks/website.rake +10 -0
  114. data/vendor/gems/celerity-0.7.6/tasks/yard.rake +16 -0
  115. data/vendor/jruby/jruby-complete-1.4.0.jar +0 -0
  116. metadata +194 -0
@@ -0,0 +1,14 @@
1
+ Feature: Check that default Rails index.html shows information
2
+ In order to value
3
+ As a role
4
+ I want feature
5
+
6
+ Scenario: Check javascript runs on static file
7
+ Given I go to the homepage
8
+ Then I should not see "Rails version"
9
+ When I follow "About your application’s environment"
10
+ And I wait for the AJAX call to finish
11
+ Then I should see "No route matches"
12
+
13
+
14
+
@@ -0,0 +1,36 @@
1
+ Feature: Installing culerity
2
+ In order to not have to use f@#$ing selenium and receive hate into our lives
3
+ As a self-respective Rails/JavaScript developer
4
+ I want to install culerity into my Rails app
5
+
6
+ Background:
7
+ Given a Rails app
8
+ And I run executable "script/generate" with arguments "cucumber"
9
+ And I delete file "features/step_definitions/webrat_steps.rb"
10
+ And I delete file "features/support/env.rb"
11
+ And I copy the project generators into "vendor/generators"
12
+ And I invoke task "rake db:migrate"
13
+ When I run executable "script/generate" with arguments "culerity"
14
+ And I setup load path to local code
15
+ And I setup the culerity javascript helpers
16
+
17
+ Scenario: Install culerity and test the rails start + stop tasks
18
+ When I invoke task "rake culerity:rails:start"
19
+ Then file "tmp/culerity_rails_server.pid" is created
20
+ And I invoke task "rake culerity:rails:stop"
21
+ Then file "tmp/culerity_rails_server.pid" is not created
22
+
23
+ Scenario: Install culerity into a Rails app and check it works
24
+ Then file "features/step_definitions/culerity_steps.rb" is created
25
+ Then file "config/environments/culerity_development.rb" is created
26
+ Then file "config/environments/culerity_continuousintegration.rb" is created
27
+
28
+ When I run executable "cucumber" with arguments "features/"
29
+ Then I should see "0 scenarios"
30
+ And I should see "0 steps"
31
+ Given I invoke task "rake culerity:rails:start"
32
+ When I add a feature file to test Rails index.html default file
33
+ And I run executable "cucumber" with arguments "features/"
34
+ Then I should see "1 scenario"
35
+ And I should see "5 steps (5 passed)"
36
+ And I should not see "WARNING: Speed up executing by running 'rake culerity:rails:start'"
@@ -0,0 +1,23 @@
1
+ Feature: Running cucumber without explicitly running external services
2
+ In order to reduce learning cost of using culerity
3
+ As a rails developer
4
+ I want the headless browser and rails processes to launch and shutdown automatically
5
+
6
+ Background:
7
+ Given a Rails app
8
+ And I run executable "script/generate" with arguments "cucumber"
9
+ And I delete file "features/step_definitions/webrat_steps.rb"
10
+ And I delete file "features/support/env.rb"
11
+ And I copy the project generators into "vendor/generators"
12
+ And I invoke task "rake db:migrate"
13
+ When I run executable "script/generate" with arguments "culerity"
14
+ And I setup load path to local code
15
+ And I setup the culerity javascript helpers
16
+
17
+ Scenario: Successfully run scenarios without requiring celerity or rails processes running
18
+ When I add a feature file to test Rails index.html default file
19
+ And I run executable "cucumber" with arguments "features/"
20
+ Then file "tmp/culerity_rails_server.pid" is not created
21
+ And I should see "1 scenario"
22
+ And I should see "5 steps (5 passed)"
23
+ And I should see "WARNING: Speed up execution by running 'rake culerity:rails:start'"
@@ -0,0 +1,175 @@
1
+ Given /^this project is active project folder/ do
2
+ @active_project_folder = File.expand_path(File.dirname(__FILE__) + "/../..")
3
+ end
4
+
5
+ Given /^env variable \$([\w_]+) set to "(.*)"/ do |env_var, value|
6
+ ENV[env_var] = value
7
+ end
8
+
9
+ Given /I delete (folder|file) "([^\"]*)"/ do |type, folder|
10
+ in_project_folder { FileUtils.rm_rf folder }
11
+ end
12
+
13
+ When /^I invoke "(.*)" generator with arguments "(.*)"$/ do |generator, arguments|
14
+ @stdout = StringIO.new
15
+ in_project_folder do
16
+ if Object.const_defined?("APP_ROOT")
17
+ APP_ROOT.replace(FileUtils.pwd)
18
+ else
19
+ APP_ROOT = FileUtils.pwd
20
+ end
21
+ run_generator(generator, arguments.split(' '), SOURCES, :stdout => @stdout)
22
+ end
23
+ File.open(File.join(@tmp_root, "generator.out"), "w") do |f|
24
+ @stdout.rewind
25
+ f << @stdout.read
26
+ end
27
+ end
28
+
29
+ When /^I run executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
30
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
31
+ in_project_folder do
32
+ system "#{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
33
+ end
34
+ end
35
+
36
+ When /^I run project executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
37
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
38
+ in_project_folder do
39
+ system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
40
+ end
41
+ end
42
+
43
+ When /^I run local executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
44
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
45
+ executable = File.expand_path(File.join(File.dirname(__FILE__), "/../../bin", executable))
46
+ in_project_folder do
47
+ system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
48
+ end
49
+ end
50
+
51
+ When /^I invoke task "rake (.*)"/ do |task|
52
+ @stdout = File.expand_path(File.join(@tmp_root, "rake.out"))
53
+ @stderr = File.expand_path(File.join(@tmp_root, "rake.err"))
54
+ in_project_folder do
55
+ system "rake #{task} --trace > #{@stdout} 2> #{@stderr}"
56
+ end
57
+ File.read(@stderr).should_not =~ /rake aborted!/
58
+ end
59
+
60
+ Then /^folder "(.*)" (is|is not) created/ do |folder, is|
61
+ in_project_folder do
62
+ File.exists?(folder).should(is == 'is' ? be_true : be_false)
63
+ end
64
+ end
65
+
66
+ Then /^file "(.*)" (is|is not) created/ do |file, is|
67
+ in_project_folder do
68
+ File.exists?(file).should(is == 'is' ? be_true : be_false)
69
+ end
70
+ end
71
+
72
+ Then /^file with name matching "(.*)" is created/ do |pattern|
73
+ in_project_folder do
74
+ Dir[pattern].should_not be_empty
75
+ end
76
+ end
77
+
78
+ Then /^file "(.*)" contents (does|does not) match \/(.*)\// do |file, does, regex|
79
+ in_project_folder do
80
+ actual_output = File.read(file)
81
+ (does == 'does') ?
82
+ actual_output.should(match(/#{regex}/)) :
83
+ actual_output.should_not(match(/#{regex}/))
84
+ end
85
+ end
86
+
87
+ Then /gem file "(.*)" and generated file "(.*)" should be the same/ do |gem_file, project_file|
88
+ File.exists?(gem_file).should be_true
89
+ File.exists?(project_file).should be_true
90
+ gem_file_contents = File.read(File.dirname(__FILE__) + "/../../#{gem_file}")
91
+ project_file_contents = File.read(File.join(@active_project_folder, project_file))
92
+ project_file_contents.should == gem_file_contents
93
+ end
94
+
95
+ Then /^(does|does not) invoke generator "(.*)"$/ do |does_invoke, generator|
96
+ actual_output = File.read(@stdout)
97
+ does_invoke == "does" ?
98
+ actual_output.should(match(/dependency\s+#{generator}/)) :
99
+ actual_output.should_not(match(/dependency\s+#{generator}/))
100
+ end
101
+
102
+ Then /help options "(.*)" and "(.*)" are displayed/ do |opt1, opt2|
103
+ actual_output = File.read(@stdout)
104
+ actual_output.should match(/#{opt1}/)
105
+ actual_output.should match(/#{opt2}/)
106
+ end
107
+
108
+ Then /^I should see "([^\"]*)"$/ do |text|
109
+ actual_output = File.read(@stdout)
110
+ actual_output.should contain(text)
111
+ end
112
+
113
+ Then /^I should not see "([^\"]*)"$/ do |text|
114
+ actual_output = File.read(@stdout)
115
+ actual_output.should_not contain(text)
116
+ end
117
+
118
+ Then /^I should see$/ do |text|
119
+ actual_output = File.read(@stdout)
120
+ actual_output.should contain(text)
121
+ end
122
+
123
+ Then /^I should not see$/ do |text|
124
+ actual_output = File.read(@stdout)
125
+ actual_output.should_not contain(text)
126
+ end
127
+
128
+ Then /^I should see exactly$/ do |text|
129
+ actual_output = File.read(@stdout)
130
+ actual_output.should == text
131
+ end
132
+
133
+ Then /^I should see all (\d+) tests pass/ do |expected_test_count|
134
+ expected = %r{^#{expected_test_count} tests, \d+ assertions, 0 failures, 0 errors}
135
+ actual_output = File.read(@stdout)
136
+ actual_output.should match(expected)
137
+ end
138
+
139
+ Then /^I should see all (\d+) examples pass/ do |expected_test_count|
140
+ expected = %r{^#{expected_test_count} examples?, 0 failures}
141
+ actual_output = File.read(@stdout)
142
+ actual_output.should match(expected)
143
+ end
144
+
145
+ Then /^yaml file "(.*)" contains (\{.*\})/ do |file, yaml|
146
+ in_project_folder do
147
+ yaml = eval yaml
148
+ YAML.load(File.read(file)).should == yaml
149
+ end
150
+ end
151
+
152
+ Then /^Rakefile can display tasks successfully/ do
153
+ @stdout = File.expand_path(File.join(@tmp_root, "rakefile.out"))
154
+ in_project_folder do
155
+ system "rake -T > #{@stdout} 2> #{@stdout}"
156
+ end
157
+ actual_output = File.read(@stdout)
158
+ actual_output.should match(/^rake\s+\w+\s+#\s.*/)
159
+ end
160
+
161
+ Then /^task "rake (.*)" is executed successfully/ do |task|
162
+ @stdout.should_not be_nil
163
+ actual_output = File.read(@stdout)
164
+ actual_output.should_not match(/^Don't know how to build task '#{task}'/)
165
+ actual_output.should_not match(/Error/i)
166
+ end
167
+
168
+ Then /^gem spec key "(.*)" contains \/(.*)\// do |key, regex|
169
+ in_project_folder do
170
+ gem_file = Dir["pkg/*.gem"].first
171
+ gem_spec = Gem::Specification.from_yaml(`gem spec #{gem_file}`)
172
+ spec_value = gem_spec.send(key.to_sym)
173
+ spec_value.to_s.should match(/#{regex}/)
174
+ end
175
+ end
@@ -0,0 +1,7 @@
1
+ When /^I setup load path to local code$/ do
2
+ project_lib_path = File.expand_path(File.dirname(__FILE__) + "/../../lib")
3
+ in_project_folder do
4
+ force_local_lib_override(:target => 'features/step_definitions/culerity_steps.rb')
5
+ end
6
+ end
7
+
@@ -0,0 +1,11 @@
1
+ Given /^I have jruby installed$/ do
2
+ @jruby_cmd = `which jruby`.strip
3
+ raise "Need to setup @jruby_cmd to test jruby environment" if @jruby_cmd.blank?
4
+ end
5
+
6
+ Then /^the gem "([^\"]*)" is installed into jruby environment$/ do |gem_name|
7
+ raise "Need to setup @jruby_cmd to test jruby environment" if @jruby_cmd.blank?
8
+ gem_list = `#{@jruby_cmd} -S gem list #{gem_name}`
9
+ gem_list.should =~ /#{gem_name}/
10
+ end
11
+
@@ -0,0 +1,36 @@
1
+ Given /^a Rails app$/ do
2
+ FileUtils.chdir(@tmp_root) do
3
+ `rails my_project`
4
+ end
5
+ @active_project_folder = File.expand_path(File.join(@tmp_root, "my_project"))
6
+ end
7
+
8
+ Given /^I copy the project generators into "([^\"]*)"$/ do |target_folder|
9
+ in_project_folder do
10
+ FileUtils.mkdir_p(target_folder)
11
+ end
12
+ `cp -rf #{File.dirname(__FILE__) + "/../../rails_generators/*"} #{File.join(@active_project_folder, target_folder)}`
13
+ end
14
+
15
+ When /^I add a feature file to test Rails index.html default file$/ do
16
+ sample_feature = File.expand_path(File.dirname(__FILE__) + "/../fixtures/sample_feature")
17
+ in_project_folder do
18
+ `cp -rf #{sample_feature} features/sample.feature`
19
+ end
20
+ end
21
+
22
+ When /^I setup the culerity javascript helpers$/ do
23
+ `cp #{File.dirname(__FILE__) + "/../fixtures/jquery"} #{File.join(@active_project_folder, 'public', 'javascripts', 'jquery.js')}`
24
+ in_project_folder do
25
+ _index = File.read('public/index.html')
26
+ File.open('public/index.html', 'w') do |f|
27
+ f << _index.sub('</head>', '<script type="text/javascript" src="javascripts/jquery.js"></script><script type="text/javascript" src="javascripts/culerity.js"></script><script type="text/javascript">jQuery.noConflict();</script></head>')
28
+ end
29
+ end
30
+ end
31
+
32
+ After do
33
+ in_project_folder do
34
+ Given 'I invoke task "rake culerity:rails:stop"'
35
+ end
36
+ end
@@ -0,0 +1,32 @@
1
+ module CommonHelpers
2
+ def in_tmp_folder(&block)
3
+ FileUtils.chdir(@tmp_root, &block)
4
+ end
5
+
6
+ def in_project_folder(&block)
7
+ project_folder = @active_project_folder || @tmp_root
8
+ FileUtils.chdir(project_folder, &block)
9
+ end
10
+
11
+ def in_home_folder(&block)
12
+ FileUtils.chdir(@home_path, &block)
13
+ end
14
+
15
+ def force_local_lib_override(options = {})
16
+ target_path = options[:target_path] || options[:target_file] || options[:target] || 'Rakefile'
17
+ in_project_folder do
18
+ contents = File.read(target_path)
19
+ File.open(target_path, "w+") do |f|
20
+ f << "$:.unshift('#{@lib_path}')\n"
21
+ f << contents
22
+ end
23
+ end
24
+ end
25
+
26
+ def setup_active_project_folder project_name
27
+ @active_project_folder = File.join(@tmp_root, project_name)
28
+ @project_name = project_name
29
+ end
30
+ end
31
+
32
+ World(CommonHelpers)
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + "/../../lib/culerity"
2
+
3
+ gem 'cucumber'
4
+ require 'cucumber'
5
+ gem 'rspec'
6
+ require 'spec'
7
+
8
+ Before do
9
+ @tmp_root = File.dirname(__FILE__) + "/../../tmp"
10
+ @home_path = File.expand_path(File.join(@tmp_root, "home"))
11
+ @lib_path = File.expand_path(File.dirname(__FILE__) + "/../../lib")
12
+ FileUtils.rm_rf @tmp_root
13
+ FileUtils.mkdir_p @home_path
14
+ ENV['HOME'] = @home_path
15
+ end
16
+
17
+ require 'rubigen'
18
+ require 'rubigen/helpers/generator_test_helper'
19
+ include RubiGen::GeneratorTestHelper
20
+ require 'rails_generator'
21
+
22
+ SOURCES = Dir[File.dirname(__FILE__) + "/../../generators"].map do |f|
23
+ RubiGen::PathSource.new(:test, File.expand_path(f))
24
+ end
@@ -0,0 +1,11 @@
1
+ module Matchers
2
+ def contain(expected)
3
+ simple_matcher("contain #{expected.inspect}") do |given, matcher|
4
+ matcher.failure_message = "expected #{given.inspect} to contain #{expected.inspect}"
5
+ matcher.negative_failure_message = "expected #{given.inspect} not to contain #{expected.inspect}"
6
+ given.index expected
7
+ end
8
+ end
9
+ end
10
+
11
+ World(Matchers)
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'rails/init'
data/lib/culerity.rb ADDED
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/culerity/remote_object_proxy'
2
+ require File.dirname(__FILE__) + '/culerity/remote_browser_proxy'
3
+ require File.dirname(__FILE__) + '/culerity/jruby_runner'
4
+
5
+ Symbol.class_eval do
6
+ def to_proc
7
+ Proc.new{|object| object.send(self)}
8
+ end
9
+ end unless :symbol.respond_to?(:to_proc)
10
+
11
+ module Culerity
12
+
13
+ module ServerCommands
14
+ def exit_server
15
+ self << '["_exit_"]'
16
+ Process.kill(6, self.pid.to_i)
17
+ end
18
+
19
+ def close_browsers
20
+ self.puts '["_close_browsers_"]'
21
+ end
22
+ end
23
+
24
+ def self.run_server
25
+ IO.popen("#{Culerity::JRubyRunner.cmd} #{__FILE__}", 'r+').extend(ServerCommands)
26
+ end
27
+
28
+ def self.run_rails(options = {})
29
+ if defined?(Rails) && !File.exists?("tmp/culerity_rails_server.pid")
30
+ puts "WARNING: Speed up execution by running 'rake culerity:rails:start'"
31
+ port = options[:port] || 3001
32
+ environment = options[:environment] || 'culerity_development'
33
+ rails_server = IO.popen("script/server -e #{environment} -p #{port}", 'r+')
34
+ sleep 5
35
+ rails_server
36
+ end
37
+ end
38
+ end
39
+
40
+ if __FILE__ == $0
41
+ require File.dirname(__FILE__) + '/culerity/celerity_server'
42
+ Culerity::CelerityServer.new STDIN, STDOUT
43
+ end
44
+
@@ -0,0 +1,81 @@
1
+ require 'rubygems'
2
+ require 'celerity'
3
+
4
+
5
+ module Culerity
6
+ class CelerityServer
7
+
8
+ def initialize(_in, _out)
9
+ @proxies = {}
10
+ @browsers = []
11
+
12
+ while(true)
13
+ call = eval _in.gets.to_s.strip
14
+ return if call == ["_exit_"]
15
+ next(close_browsers) if call == ["_close_browsers_"]
16
+ unless call.nil?
17
+ begin
18
+ # check if last arg is a block
19
+ if call.last.is_a?(Proc)
20
+ # pass as &call[-1]
21
+ result = target(call.first).send call[1], *call[2..-2], &call[-1]
22
+ else
23
+ # just call with args as normal
24
+ result = target(call.first).send call[1], *call[2..-1]
25
+ end
26
+ _out << "[:return, #{proxify result}]\n"
27
+ rescue => e
28
+ _out << "[:exception, \"#{e.class.name}\", #{e.message.inspect}, #{e.backtrace.inspect}]\n"
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+
36
+ private
37
+
38
+ def configure_browser(options)
39
+ @browser_options = options
40
+ end
41
+
42
+ def new_browser(options, number = nil)
43
+ number ||= @browsers.size
44
+ @browsers[number] = Celerity::Browser.new(options || @browser_options || {})
45
+ "browser#{number}"
46
+ end
47
+
48
+ def close_browsers
49
+ @browsers.each { |browser| browser.close }
50
+ @browsers = []
51
+ end
52
+
53
+ def browser(number)
54
+ unless @browsers[number]
55
+ new_browser(nil, number)
56
+ end
57
+ @browsers[number]
58
+ end
59
+
60
+ def target(object_id)
61
+ if object_id =~ /browser(\d+)/
62
+ browser($1.to_i)
63
+ elsif object_id == 'celerity'
64
+ self
65
+ else
66
+ @proxies[object_id]
67
+ end
68
+ end
69
+
70
+ def proxify(result)
71
+ if result.is_a?(Array)
72
+ "[" + result.map {|x| proxify(x) }.join(", ") + "]"
73
+ elsif [String, TrueClass, FalseClass, Fixnum, Float, NilClass].include?(result.class)
74
+ result.inspect
75
+ else
76
+ @proxies[result.object_id] = result
77
+ "Culerity::RemoteObjectProxy.new(#{result.object_id}, @io)"
78
+ end
79
+ end
80
+ end
81
+ end