langalex-culerity 0.1.7 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -1
- data/README.textile +14 -9
- data/Rakefile +7 -6
- data/VERSION.yml +2 -2
- data/culerity.gemspec +19 -5
- data/features/fixtures/sample_feature +14 -0
- data/features/installing_culerity.feature +46 -0
- data/features/step_definitions/common_steps.rb +171 -0
- data/features/step_definitions/culerity_setup_steps.rb +7 -0
- data/features/step_definitions/rails_setup_steps.rb +36 -0
- data/features/support/common.rb +32 -0
- data/features/support/env.rb +24 -0
- data/features/support/matchers.rb +11 -0
- data/lib/culerity/celerity_server.rb +32 -9
- data/lib/culerity/remote_browser_proxy.rb +15 -9
- data/lib/culerity/remote_object_proxy.rb +31 -11
- data/lib/culerity.rb +36 -1
- data/rails_generators/culerity/culerity_generator.rb +25 -0
- data/rails_generators/culerity/templates/config/environments/culerity_continuousintegration.rb +28 -0
- data/rails_generators/culerity/templates/config/environments/culerity_development.rb +17 -0
- data/{generators/culerity/templates/common_celerity.rb → rails_generators/culerity/templates/features/step_definitions/common_celerity_steps.rb} +2 -2
- data/rails_generators/culerity/templates/lib/tasks/culerity.rake +34 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/celerity_server_spec.rb +36 -16
- data/spec/remote_browser_proxy_spec.rb +30 -19
- data/spec/remote_object_proxy_spec.rb +34 -2
- metadata +20 -5
- data/generators/culerity/culerity_generator.rb +0 -20
data/.gitignore
CHANGED
data/README.textile
CHANGED
@@ -19,10 +19,6 @@ First download JRuby and unpack it to some location, for example $HOME/jruby. Ma
|
|
19
19
|
|
20
20
|
<pre><code> ln -s $HOME/jruby/bin/jruby /usr/bin/jruby</code></pre>
|
21
21
|
|
22
|
-
Next install the celerity gem for JRuby:
|
23
|
-
|
24
|
-
<pre><code> jruby -S gem install celerity</code></pre>
|
25
|
-
|
26
22
|
Now (assuming you have a Rails application set up already) install Culerity as a Rails Plugin:
|
27
23
|
|
28
24
|
<pre><code> cd RAILS_ROOT
|
@@ -40,18 +36,27 @@ Run the RSpec, Cucumber and Culerity generators:
|
|
40
36
|
script/generate cucumber
|
41
37
|
script/generate culerity
|
42
38
|
</code></pre>
|
43
|
-
|
44
|
-
This creates the features folder and a file common_celerity.rb into your application. This file contains step definitions for basic interactions like clicking links or filling out forms.
|
45
39
|
|
46
|
-
|
40
|
+
This creates the features folder and a file common_celerity.rb into your application. This file contains step definitions for basic interactions like clicking links or filling out forms.
|
47
41
|
|
48
|
-
|
42
|
+
Culerity is a Ruby-side interface to celerity running on JRuby. To install it:
|
49
43
|
|
44
|
+
<pre><code> rake culerity:install</code></pre>
|
50
45
|
|
51
|
-
|
46
|
+
After you have written a first feature you can run it just like you would run a standard cucumber feature. The only difference is that you have to start a web server (e.g. mongrel) with the test environment enabled beforehand.
|
47
|
+
|
48
|
+
<pre><code> rake culerity:rails:start
|
52
49
|
cucumber features/my_feature.feature
|
53
50
|
</code></pre>
|
54
51
|
|
52
|
+
The Rails instance uses a special environment culerity_development.
|
53
|
+
|
54
|
+
When you have finished running culerity/cucumber you can turn off the Rails instance:
|
55
|
+
|
56
|
+
NOTE: The default port for this server is 3001. You can change this in features/step_definitions/common_celerity.rb
|
57
|
+
|
58
|
+
<pre><code> rake culerity:rails:stop</code></pre>
|
59
|
+
|
55
60
|
h2. How does it work
|
56
61
|
|
57
62
|
While Celerity is based on Java and requires JRuby to run, with Culerity you can still run your tests in your own Ruby Environment. When you run your features a separate JRuby process for Celerity is spawned and all Celerity Commands are redirected to this other process.
|
data/Rakefile
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rake/testtask'
|
3
3
|
require 'rake/rdoctask'
|
4
|
-
require 'rcov/rcovtask'
|
4
|
+
# require 'rcov/rcovtask'
|
5
5
|
|
6
6
|
begin
|
7
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
7
8
|
require 'jeweler'
|
8
9
|
Jeweler::Tasks.new do |s|
|
9
10
|
s.name = "culerity"
|
@@ -33,10 +34,10 @@ Rake::RDocTask.new do |rdoc|
|
|
33
34
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
34
35
|
end
|
35
36
|
|
36
|
-
Rcov::RcovTask.new do |t|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
37
|
+
# Rcov::RcovTask.new do |t|
|
38
|
+
# t.libs << 'spec'
|
39
|
+
# t.test_files = FileList['spec/**/*_spec.rb']
|
40
|
+
# t.verbose = true
|
41
|
+
# end
|
41
42
|
|
42
43
|
task :default => :test
|
data/VERSION.yml
CHANGED
data/culerity.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{culerity}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.2.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Alexander Lang"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-08-16}
|
10
10
|
s.description = %q{Culerity integrates Cucumber and Celerity in order to test your application's full stack.}
|
11
11
|
s.email = %q{alex@upstream-berlin.com}
|
12
12
|
s.extra_rdoc_files = [
|
@@ -19,14 +19,28 @@ Gem::Specification.new do |s|
|
|
19
19
|
"Rakefile",
|
20
20
|
"VERSION.yml",
|
21
21
|
"culerity.gemspec",
|
22
|
-
"
|
23
|
-
"
|
22
|
+
"features/fixtures/sample_feature",
|
23
|
+
"features/installing_culerity.feature",
|
24
|
+
"features/step_definitions/common_steps.rb",
|
25
|
+
"features/step_definitions/culerity_setup_steps.rb",
|
26
|
+
"features/step_definitions/rails_setup_steps.rb",
|
27
|
+
"features/support/common.rb",
|
28
|
+
"features/support/env.rb",
|
29
|
+
"features/support/matchers.rb",
|
24
30
|
"init.rb",
|
25
31
|
"lib/culerity.rb",
|
26
32
|
"lib/culerity/celerity_server.rb",
|
27
33
|
"lib/culerity/remote_browser_proxy.rb",
|
28
34
|
"lib/culerity/remote_object_proxy.rb",
|
29
35
|
"rails/init.rb",
|
36
|
+
"rails_generators/culerity/culerity_generator.rb",
|
37
|
+
"rails_generators/culerity/templates/config/environments/culerity_continuousintegration.rb",
|
38
|
+
"rails_generators/culerity/templates/config/environments/culerity_development.rb",
|
39
|
+
"rails_generators/culerity/templates/features/step_definitions/common_celerity_steps.rb",
|
40
|
+
"rails_generators/culerity/templates/lib/tasks/culerity.rake",
|
41
|
+
"script/console",
|
42
|
+
"script/destroy",
|
43
|
+
"script/generate",
|
30
44
|
"spec/celerity_server_spec.rb",
|
31
45
|
"spec/remote_browser_proxy_spec.rb",
|
32
46
|
"spec/remote_object_proxy_spec.rb",
|
@@ -35,7 +49,7 @@ Gem::Specification.new do |s|
|
|
35
49
|
s.homepage = %q{http://github.com/langalex/culerity}
|
36
50
|
s.rdoc_options = ["--charset=UTF-8"]
|
37
51
|
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = %q{1.3.
|
52
|
+
s.rubygems_version = %q{1.3.3}
|
39
53
|
s.summary = %q{Culerity integrates Cucumber and Celerity in order to test your application's full stack.}
|
40
54
|
s.test_files = [
|
41
55
|
"spec/celerity_server_spec.rb",
|
@@ -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,46 @@
|
|
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 copy the project generators into "vendor/generators"
|
11
|
+
And I invoke task "rake db:migrate"
|
12
|
+
When I run executable "script/generate" with arguments "culerity"
|
13
|
+
And I setup load path to local code
|
14
|
+
|
15
|
+
|
16
|
+
Scenario: Install culerity and setup jruby environment
|
17
|
+
Given I have jruby installed
|
18
|
+
When I invoke task "rake culerity:install"
|
19
|
+
Then the gem "jarib-celerity" is installed into jruby environment
|
20
|
+
|
21
|
+
Scenario: Install culerity and test the rails start + stop tasks
|
22
|
+
When I invoke task "rake culerity:rails:start"
|
23
|
+
Then file "tmp/culerity_rails_server.pid" is created
|
24
|
+
And I invoke task "rake culerity:rails:stop"
|
25
|
+
Then file "tmp/culerity_rails_server.pid" is not created
|
26
|
+
|
27
|
+
Scenario: Install culerity into a Rails app and check it works
|
28
|
+
Then file "features/step_definitions/common_celerity_steps.rb" is created
|
29
|
+
Then file "config/environments/culerity_development.rb" is created
|
30
|
+
Then file "config/environments/culerity_continuousintegration.rb" is created
|
31
|
+
|
32
|
+
And I run executable "cucumber" with arguments "features/"
|
33
|
+
Then I should see "0 scenarios"
|
34
|
+
And I should see "0 steps"
|
35
|
+
|
36
|
+
Given I invoke task "rake culerity:rails:start"
|
37
|
+
|
38
|
+
When I add a feature file to test Rails index.html default file
|
39
|
+
And I run executable "cucumber" with arguments "features/"
|
40
|
+
Then I should see "1 scenario"
|
41
|
+
And I should see "5 steps (5 passed)"
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
@@ -0,0 +1,171 @@
|
|
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
|
+
|
114
|
+
Then /^I should see$/ do |text|
|
115
|
+
actual_output = File.read(@stdout)
|
116
|
+
actual_output.should contain(text)
|
117
|
+
end
|
118
|
+
|
119
|
+
Then /^I should not see$/ do |text|
|
120
|
+
actual_output = File.read(@stdout)
|
121
|
+
actual_output.should_not contain(text)
|
122
|
+
end
|
123
|
+
|
124
|
+
Then /^I should see exactly$/ do |text|
|
125
|
+
actual_output = File.read(@stdout)
|
126
|
+
actual_output.should == text
|
127
|
+
end
|
128
|
+
|
129
|
+
Then /^I should see all (\d+) tests pass/ do |expected_test_count|
|
130
|
+
expected = %r{^#{expected_test_count} tests, \d+ assertions, 0 failures, 0 errors}
|
131
|
+
actual_output = File.read(@stdout)
|
132
|
+
actual_output.should match(expected)
|
133
|
+
end
|
134
|
+
|
135
|
+
Then /^I should see all (\d+) examples pass/ do |expected_test_count|
|
136
|
+
expected = %r{^#{expected_test_count} examples?, 0 failures}
|
137
|
+
actual_output = File.read(@stdout)
|
138
|
+
actual_output.should match(expected)
|
139
|
+
end
|
140
|
+
|
141
|
+
Then /^yaml file "(.*)" contains (\{.*\})/ do |file, yaml|
|
142
|
+
in_project_folder do
|
143
|
+
yaml = eval yaml
|
144
|
+
YAML.load(File.read(file)).should == yaml
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
Then /^Rakefile can display tasks successfully/ do
|
149
|
+
@stdout = File.expand_path(File.join(@tmp_root, "rakefile.out"))
|
150
|
+
in_project_folder do
|
151
|
+
system "rake -T > #{@stdout} 2> #{@stdout}"
|
152
|
+
end
|
153
|
+
actual_output = File.read(@stdout)
|
154
|
+
actual_output.should match(/^rake\s+\w+\s+#\s.*/)
|
155
|
+
end
|
156
|
+
|
157
|
+
Then /^task "rake (.*)" is executed successfully/ do |task|
|
158
|
+
@stdout.should_not be_nil
|
159
|
+
actual_output = File.read(@stdout)
|
160
|
+
actual_output.should_not match(/^Don't know how to build task '#{task}'/)
|
161
|
+
actual_output.should_not match(/Error/i)
|
162
|
+
end
|
163
|
+
|
164
|
+
Then /^gem spec key "(.*)" contains \/(.*)\// do |key, regex|
|
165
|
+
in_project_folder do
|
166
|
+
gem_file = Dir["pkg/*.gem"].first
|
167
|
+
gem_spec = Gem::Specification.from_yaml(`gem spec #{gem_file}`)
|
168
|
+
spec_value = gem_spec.send(key.to_sym)
|
169
|
+
spec_value.to_s.should match(/#{regex}/)
|
170
|
+
end
|
171
|
+
end
|
@@ -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
|
+
Given /^I run the rails server in environment "([^\"]*)"$/ do |environment|
|
23
|
+
in_project_folder do
|
24
|
+
$rails_server ||= IO.popen("script/server -e #{environment} -p 3001", 'r+')
|
25
|
+
File.open("tmp/culerity_rails_server.pid", "w") { |file| file << $rails_server.pid; file.flush }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
After do
|
30
|
+
in_project_folder do
|
31
|
+
Given 'I invoke task "rake culerity:rails:stop"'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# rake culerity:rails:start [RAILS=culerity_development]
|
36
|
+
# rake culerity:rails:stop
|
@@ -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)
|
@@ -7,19 +7,28 @@ module Culerity
|
|
7
7
|
|
8
8
|
def initialize(_in, _out)
|
9
9
|
@proxies = {}
|
10
|
-
@
|
11
|
-
|
10
|
+
@browsers = []
|
11
|
+
|
12
12
|
while(true)
|
13
13
|
call = eval _in.gets.to_s.strip
|
14
|
-
return
|
14
|
+
return if call == ["_exit_"]
|
15
|
+
next(close_browsers) if call == ["_close_browsers_"]
|
15
16
|
unless call.nil?
|
16
17
|
begin
|
17
|
-
|
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
|
18
26
|
_out << "[:return, #{proxify result}]\n"
|
19
27
|
rescue => e
|
20
28
|
_out << "[:exception, \"#{e.class.name}\", #{e.message.inspect}, #{e.backtrace.inspect}]\n"
|
21
29
|
end
|
22
30
|
end
|
31
|
+
|
23
32
|
end
|
24
33
|
|
25
34
|
end
|
@@ -30,13 +39,27 @@ module Culerity
|
|
30
39
|
@browser_options = options
|
31
40
|
end
|
32
41
|
|
33
|
-
def
|
34
|
-
|
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]
|
35
58
|
end
|
36
59
|
|
37
60
|
def target(object_id)
|
38
|
-
if object_id
|
39
|
-
browser
|
61
|
+
if object_id =~ /browser(\d+)/
|
62
|
+
browser($1.to_i)
|
40
63
|
elsif object_id == 'celerity'
|
41
64
|
self
|
42
65
|
else
|
@@ -55,4 +78,4 @@ module Culerity
|
|
55
78
|
end
|
56
79
|
end
|
57
80
|
end
|
58
|
-
end
|
81
|
+
end
|
@@ -3,11 +3,8 @@ module Culerity
|
|
3
3
|
class RemoteBrowserProxy < RemoteObjectProxy
|
4
4
|
def initialize(io, browser_options = {})
|
5
5
|
@io = io
|
6
|
-
|
7
|
-
|
8
|
-
configure_browser browser_options
|
9
|
-
@remote_object_id = nil
|
10
|
-
end
|
6
|
+
@remote_object_id = "celerity".inspect
|
7
|
+
@remote_object_id = new_browser(browser_options).inspect
|
11
8
|
end
|
12
9
|
|
13
10
|
#
|
@@ -42,11 +39,20 @@ module Culerity
|
|
42
39
|
true
|
43
40
|
end
|
44
41
|
|
45
|
-
private
|
46
42
|
|
47
|
-
|
48
|
-
|
43
|
+
#
|
44
|
+
# Specify whether to accept or reject all confirm js dialogs
|
45
|
+
# for the code in the block that's run.
|
46
|
+
#
|
47
|
+
def confirm(bool, &block)
|
48
|
+
blk = "lambda { #{bool} }"
|
49
|
+
|
50
|
+
self.send_remote(:add_listener, :confirm) { blk }
|
51
|
+
block.call
|
52
|
+
self.send_remote(:remove_listener, :confirm) { blk }
|
49
53
|
end
|
54
|
+
|
50
55
|
end
|
51
56
|
|
52
|
-
|
57
|
+
|
58
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Culerity
|
2
|
-
|
2
|
+
|
3
3
|
class CulerityException < StandardError
|
4
4
|
def initialize(message, backtrace)
|
5
5
|
super message
|
@@ -12,7 +12,7 @@ module Culerity
|
|
12
12
|
@remote_object_id = remote_object_id
|
13
13
|
@io = io
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
#
|
17
17
|
# Commonly used to get the HTML id attribute
|
18
18
|
# Use `object_id` to get the local objects' id.
|
@@ -20,26 +20,32 @@ module Culerity
|
|
20
20
|
def id
|
21
21
|
send_remote(:id)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def method_missing(name, *args)
|
25
25
|
send_remote(name, *args)
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
#
|
29
29
|
# Calls the passed method on the remote object with any arguments specified.
|
30
30
|
# Behaves the same as <code>Object#send</code>.
|
31
31
|
#
|
32
|
-
|
33
|
-
|
32
|
+
# If you pass it a block then it will append the block as a "lambda { … }".
|
33
|
+
# If your block returns a lambda string ("lambda { … }") then it will be passed
|
34
|
+
# straight through, otherwise it will be wrapped in a lambda string before sending.
|
35
|
+
#
|
36
|
+
def send_remote(name, *args, &blk)
|
37
|
+
input = [remote_object_id, %Q{"#{name}"}, *args.map{|a| a.inspect}]
|
38
|
+
input << block_to_string(&blk) if block_given?
|
39
|
+
@io << "[#{input.join(", ")}]\n"
|
34
40
|
process_result @io.gets.to_s.strip
|
35
41
|
end
|
36
|
-
|
42
|
+
|
37
43
|
def exit
|
38
44
|
@io << '["_exit_"]'
|
39
45
|
end
|
40
|
-
|
46
|
+
|
41
47
|
private
|
42
|
-
|
48
|
+
|
43
49
|
def process_result(result)
|
44
50
|
res = eval result
|
45
51
|
if res.first == :return
|
@@ -48,9 +54,23 @@ module Culerity
|
|
48
54
|
raise CulerityException.new("#{res[1]}: #{res[2]}", res[3])
|
49
55
|
end
|
50
56
|
end
|
51
|
-
|
57
|
+
|
58
|
+
#
|
59
|
+
# Takes a block and either returns the result (if it returns "lambda { … }")
|
60
|
+
# or builds the lambda string with the result of the block in it.
|
61
|
+
#
|
62
|
+
# Returns a string in the format "lambda { … }"
|
63
|
+
#
|
64
|
+
def block_to_string &block
|
65
|
+
result = block.call.to_s
|
66
|
+
unless result.is_a?(String) && result[/^lambda \s* \{ .*? \}/x]
|
67
|
+
result = "lambda { #{result} }"
|
68
|
+
end
|
69
|
+
result
|
70
|
+
end
|
71
|
+
|
52
72
|
def remote_object_id
|
53
73
|
@remote_object_id
|
54
74
|
end
|
55
75
|
end
|
56
|
-
end
|
76
|
+
end
|
data/lib/culerity.rb
CHANGED
@@ -3,13 +3,48 @@ require File.dirname(__FILE__) + '/culerity/remote_browser_proxy'
|
|
3
3
|
|
4
4
|
module Culerity
|
5
5
|
|
6
|
+
module ServerCommands
|
7
|
+
def exit_server
|
8
|
+
self << '["_exit_"]'
|
9
|
+
close
|
10
|
+
end
|
11
|
+
|
12
|
+
def close_browsers
|
13
|
+
self.puts '["_close_browsers_"]'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
6
17
|
def self.run_server
|
7
|
-
IO.popen("jruby #{__FILE__}", 'r+')
|
18
|
+
IO.popen("jruby #{__FILE__}", 'r+').extend(ServerCommands)
|
19
|
+
|
20
|
+
# open the two pipes that were created below
|
21
|
+
# while(!File.exists?("tmp/culerity_in.pipe"))
|
22
|
+
# sleep(1)
|
23
|
+
# end
|
24
|
+
# pipe_in = open("tmp/culerity_in.pipe", "w+")
|
25
|
+
# pipe_out = open("tmp/culerity_out.pipe", "r+")
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
# store celerity pid in tmp/culerity_celerity.pid
|
30
|
+
# store server pid in tmp/culerity_rails_server.pid
|
31
|
+
|
32
|
+
# open named pipes to communicate with celerity_server + return them
|
8
33
|
end
|
9
34
|
|
10
35
|
end
|
11
36
|
|
12
37
|
if __FILE__ == $0
|
38
|
+
# `rm tmp/culerity_in.pipe`
|
39
|
+
# `mkfifo tmp/culerity_in.pipe`
|
40
|
+
# `rm tmp/culerity_out.pipe`
|
41
|
+
# `mkfifo tmp/culerity_out.pipe`
|
42
|
+
#
|
43
|
+
# pipe_in = open("tmp/culerity_in.pipe", "r+")
|
44
|
+
# p pipe_in
|
45
|
+
# p STDIN
|
46
|
+
# pipe_out = open("tmp/culerity_out.pipe", "w+")
|
47
|
+
#
|
13
48
|
require File.dirname(__FILE__) + '/culerity/celerity_server'
|
14
49
|
Culerity::CelerityServer.new STDIN, STDOUT
|
15
50
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class CulerityGenerator < Rails::Generator::Base
|
2
|
+
|
3
|
+
def manifest
|
4
|
+
record do |m|
|
5
|
+
m.directory 'features/step_definitions'
|
6
|
+
m.file 'features/step_definitions/common_celerity_steps.rb', 'features/step_definitions/common_celerity_steps.rb'
|
7
|
+
m.file 'config/environments/culerity_continuousintegration.rb', 'config/environments/culerity_continuousintegration.rb'
|
8
|
+
m.file 'config/environments/culerity_development.rb', 'config/environments/culerity_development.rb'
|
9
|
+
|
10
|
+
m.gsub_file 'config/database.yml', /cucumber:.*\n/, "cucumber: &CUCUMBER\n"
|
11
|
+
|
12
|
+
m.gsub_file 'config/database.yml', /\z/, "\nculerity_development:\n <<: *CUCUMBER"
|
13
|
+
m.gsub_file 'config/database.yml', /\z/, "\nculerity_continuousintegration:\n <<: *CUCUMBER"
|
14
|
+
|
15
|
+
m.file "lib/tasks/culerity.rake", "lib/tasks/culerity.rake"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def banner
|
22
|
+
"Usage: #{$0} culerity"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/rails_generators/culerity/templates/config/environments/culerity_continuousintegration.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
2
|
+
|
3
|
+
# The production environment is meant for finished, "live" apps.
|
4
|
+
# Code is not reloaded between requests
|
5
|
+
config.cache_classes = true
|
6
|
+
|
7
|
+
# Full error reports are disabled and caching is turned on
|
8
|
+
config.action_controller.consider_all_requests_local = false
|
9
|
+
config.action_controller.perform_caching = true
|
10
|
+
config.action_view.cache_template_loading = true
|
11
|
+
|
12
|
+
# See everything in the log (default is :info)
|
13
|
+
# config.log_level = :debug
|
14
|
+
|
15
|
+
# Use a different logger for distributed setups
|
16
|
+
# config.logger = SyslogLogger.new
|
17
|
+
|
18
|
+
# Use a different cache store in production
|
19
|
+
# config.cache_store = :mem_cache_store
|
20
|
+
|
21
|
+
# Enable serving of images, stylesheets, and javascripts from an asset server
|
22
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
23
|
+
|
24
|
+
# Disable delivery errors, bad email addresses will be ignored
|
25
|
+
# config.action_mailer.raise_delivery_errors = false
|
26
|
+
|
27
|
+
# Enable threaded mode
|
28
|
+
# config.threadsafe!
|
@@ -0,0 +1,17 @@
|
|
1
|
+
config.cache_classes = false
|
2
|
+
|
3
|
+
# Log error messages when you accidentally call methods on nil.
|
4
|
+
config.whiny_nils = true
|
5
|
+
|
6
|
+
# Show full error reports and disable caching
|
7
|
+
config.action_controller.consider_all_requests_local = true
|
8
|
+
config.action_controller.perform_caching = false
|
9
|
+
config.action_view.cache_template_loading = false
|
10
|
+
|
11
|
+
# Disable request forgery protection in test environment
|
12
|
+
config.action_controller.allow_forgery_protection = false
|
13
|
+
|
14
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
15
|
+
# The :test delivery method accumulates sent emails in the
|
16
|
+
# ActionMailer::Base.deliveries array.
|
17
|
+
config.action_mailer.delivery_method = :test
|
@@ -0,0 +1,34 @@
|
|
1
|
+
namespace 'culerity' do
|
2
|
+
namespace 'rails' do
|
3
|
+
desc "Starts a rails server for cucumber/culerity tests"
|
4
|
+
task :start => :environment do
|
5
|
+
environment = 'culerity_development'
|
6
|
+
pid_file = RAILS_ROOT + "/tmp/culerity_rails_server.pid"
|
7
|
+
if File.exists?(pid_file)
|
8
|
+
puts "culerity rails server already running; if not, delete tmp/culerity_rails_server.pid and try again"
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
rails_server = IO.popen("script/server -e #{environment} -p 3001", 'r+')
|
12
|
+
File.open(pid_file, "w") { |file| file << rails_server.pid }
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Stops the running rails server for cucumber/culerity tests"
|
16
|
+
task :stop => :environment do
|
17
|
+
pid_file = RAILS_ROOT + "/tmp/culerity_rails_server.pid"
|
18
|
+
if File.exists?(pid_file)
|
19
|
+
pid = File.read(pid_file).to_i
|
20
|
+
Process.kill(6, pid)
|
21
|
+
File.delete(pid_file)
|
22
|
+
else
|
23
|
+
puts "No culerity rails server running. Doing nothing."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "Install required gems into jruby"
|
29
|
+
task :install => :environment do
|
30
|
+
jgem_cmd = `which jgem`.strip
|
31
|
+
raise "ERROR: You need to install jruby to use culerity and celerity." if jgem_cmd.blank?
|
32
|
+
sh "#{jgem_cmd} install jarib-celerity --source=http://gems.github.com"
|
33
|
+
end
|
34
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/culerity.rb'}"
|
9
|
+
puts "Loading culerity gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -6,18 +6,45 @@ describe Culerity::CelerityServer do
|
|
6
6
|
Celerity::Browser.stub!(:new).and_return(@browser)
|
7
7
|
end
|
8
8
|
|
9
|
-
it "should pass the method call to the
|
9
|
+
it "should pass the method call to the celerity browser" do
|
10
10
|
@browser.should_receive(:goto).with('/homepage')
|
11
11
|
_in = stub 'in'
|
12
|
-
_in.stub!(:gets).and_return("[\"
|
12
|
+
_in.stub!(:gets).and_return("[\"browser0\", \"goto\", \"/homepage\"]\n", "[\"_exit_\"]\n")
|
13
13
|
_out = stub 'out', :<< => nil
|
14
14
|
Culerity::CelerityServer.new(_in, _out)
|
15
15
|
end
|
16
|
+
|
17
|
+
it "should return the browser id when a new browser is requested" do
|
18
|
+
_in = stub 'in'
|
19
|
+
_in.stub!(:gets).and_return("[\"celerity\", \"new_browser\", {}]\n", "[\"_exit_\"]\n")
|
20
|
+
_out = stub 'out'
|
21
|
+
_out.should_receive(:<<).with("[:return, \"browser0\"]\n")
|
22
|
+
Culerity::CelerityServer.new(_in, _out)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should create a new browser with the provided options" do
|
26
|
+
_in = stub 'in'
|
27
|
+
_in.stub!(:gets).and_return("[\"celerity\", \"new_browser\", {:browser => :firefox}]\n", "[\"_exit_\"]\n")
|
28
|
+
Celerity::Browser.should_receive(:new).with(:browser => :firefox)
|
29
|
+
Culerity::CelerityServer.new(_in, stub.as_null_object)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should create multiple browsers and return the appropriate id for each" do
|
33
|
+
_in = stub 'in'
|
34
|
+
_in.stub!(:gets).and_return("[\"celerity\", \"new_browser\", {}]\n", "[\"celerity\", \"new_browser\", {}]\n", "[\"_exit_\"]\n")
|
35
|
+
Celerity::Browser.should_receive(:new).twice
|
36
|
+
_out = stub 'out'
|
37
|
+
_out.should_receive(:<<).with("[:return, \"browser0\"]\n").ordered
|
38
|
+
_out.should_receive(:<<).with("[:return, \"browser1\"]\n").ordered
|
39
|
+
Culerity::CelerityServer.new(_in, _out)
|
40
|
+
|
41
|
+
end
|
42
|
+
|
16
43
|
|
17
44
|
it "should send back the return value of the call" do
|
18
45
|
@browser.stub!(:goto).and_return(true)
|
19
46
|
_in = stub 'in'
|
20
|
-
_in.stub!(:gets).and_return("[\"
|
47
|
+
_in.stub!(:gets).and_return("[\"browser0\", \"goto\", \"/homepage\"]\n", "[\"_exit_\"]\n")
|
21
48
|
_out = stub 'out'
|
22
49
|
_out.should_receive(:<<).with("[:return, true]\n")
|
23
50
|
Culerity::CelerityServer.new(_in, _out)
|
@@ -34,7 +61,7 @@ describe Culerity::CelerityServer do
|
|
34
61
|
it "should send back a proxy if the return value is not a string, number, nil or boolean" do
|
35
62
|
@browser.stub!(:goto).and_return(stub('123', :object_id => 456))
|
36
63
|
_in = stub 'in'
|
37
|
-
_in.stub!(:gets).and_return("[\"
|
64
|
+
_in.stub!(:gets).and_return("[\"browser0\", \"goto\", \"/homepage\"]\n", "[\"_exit_\"]\n")
|
38
65
|
_out = stub 'out'
|
39
66
|
_out.should_receive(:<<).with("[:return, Culerity::RemoteObjectProxy.new(456, @io)]\n")
|
40
67
|
Culerity::CelerityServer.new(_in, _out)
|
@@ -44,24 +71,17 @@ describe Culerity::CelerityServer do
|
|
44
71
|
proxy = stub('123', :object_id => 456)
|
45
72
|
@browser.stub!(:goto).and_return(proxy)
|
46
73
|
_in = stub 'in'
|
47
|
-
_in.stub!(:gets).and_return("[\"
|
74
|
+
_in.stub!(:gets).and_return("[\"browser0\", \"goto\", \"/homepage\"]\n", "[456, \"goto_2\", \"1\"]", "[\"_exit_\"]\n")
|
48
75
|
_out = stub 'out', :<< => nil
|
49
76
|
proxy.should_receive(:goto_2).with('1')
|
50
77
|
Culerity::CelerityServer.new(_in, _out)
|
51
78
|
end
|
52
|
-
|
53
|
-
it "should configure the browser" do
|
54
|
-
_in = stub 'in'
|
55
|
-
_in.stub!(:gets).and_return('["celerity", "configure_browser", {:browser=>:firefox}]' + "\n", '["browser", "goto", "/homepage"]' + "\n", "[\"_exit_\"]\n")
|
56
|
-
Celerity::Browser.should_receive(:new).with(:browser => :firefox)
|
57
|
-
Culerity::CelerityServer.new(_in, stub.as_null_object)
|
58
|
-
end
|
59
|
-
|
79
|
+
|
60
80
|
it "should pass multiple method calls" do
|
61
81
|
@browser.should_receive(:goto).with('/homepage')
|
62
82
|
@browser.should_receive(:goto).with('/page2')
|
63
83
|
_in = stub 'in'
|
64
|
-
_in.stub!(:gets).and_return("[\"
|
84
|
+
_in.stub!(:gets).and_return("[\"browser0\", \"goto\", \"/homepage\"]\n", "[\"browser0\", \"goto\", \"/page2\"]\n", "[\"_exit_\"]\n")
|
65
85
|
_out = stub 'out', :<< => nil
|
66
86
|
Culerity::CelerityServer.new(_in, _out)
|
67
87
|
end
|
@@ -69,9 +89,9 @@ describe Culerity::CelerityServer do
|
|
69
89
|
it "should return an exception" do
|
70
90
|
@browser.stub!(:goto).and_raise(RuntimeError.new('test exception with "quotes"'))
|
71
91
|
_in = stub 'in'
|
72
|
-
_in.stub!(:gets).and_return("[\"
|
92
|
+
_in.stub!(:gets).and_return("[\"browser0\", \"goto\", \"/homepage\"]\n", "[\"_exit_\"]\n")
|
73
93
|
_out = stub 'out'
|
74
94
|
_out.should_receive(:<<).with(/^\[:exception, \"RuntimeError\", \"test exception with \\\"quotes\\\"\", \[.*\]\]\n$/)
|
75
95
|
Culerity::CelerityServer.new(_in, _out)
|
76
96
|
end
|
77
|
-
end
|
97
|
+
end
|
@@ -1,10 +1,13 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
3
|
describe Culerity::RemoteBrowserProxy do
|
4
|
+
before(:each) do
|
5
|
+
@io = stub 'io', :gets => "[:return, \"browser0\"]", :<< => nil
|
6
|
+
end
|
4
7
|
it "should send the serialized method call to the output" do
|
5
|
-
io
|
6
|
-
io.should_receive(:<<).with("[\"
|
7
|
-
proxy = Culerity::RemoteBrowserProxy.new io
|
8
|
+
@io.should_receive(:<<).with("[\"celerity\", \"new_browser\", {}]\n").ordered
|
9
|
+
@io.should_receive(:<<).with("[\"browser0\", \"goto\", \"/homepage\"]\n").ordered
|
10
|
+
proxy = Culerity::RemoteBrowserProxy.new @io
|
8
11
|
proxy.goto '/homepage'
|
9
12
|
end
|
10
13
|
|
@@ -15,37 +18,45 @@ describe Culerity::RemoteBrowserProxy do
|
|
15
18
|
end
|
16
19
|
|
17
20
|
it "should send the brower options to the remote server" do
|
18
|
-
io = stub 'io', :gets => "[:return,
|
19
|
-
io.should_receive(:<<).with('["celerity", "
|
21
|
+
io = stub 'io', :gets => "[:return, \"browser0\"]"
|
22
|
+
io.should_receive(:<<).with('["celerity", "new_browser", {:browser=>:firefox}]' + "\n")
|
20
23
|
proxy = Culerity::RemoteBrowserProxy.new io, {:browser => :firefox}
|
21
24
|
end
|
22
25
|
|
23
26
|
it "should timeout if wait_until takes too long" do
|
24
|
-
|
25
|
-
proxy = Culerity::RemoteBrowserProxy.new io
|
27
|
+
proxy = Culerity::RemoteBrowserProxy.new @io
|
26
28
|
lambda {
|
27
|
-
proxy.wait_until(1) { false }
|
29
|
+
proxy.wait_until(0.1) { false }
|
28
30
|
}.should raise_error(Timeout::Error)
|
29
31
|
end
|
30
32
|
|
31
33
|
it "should return successfully when wait_until returns true" do
|
32
|
-
|
33
|
-
proxy
|
34
|
-
proxy.wait_until(1) { true }.should == true
|
34
|
+
proxy = Culerity::RemoteBrowserProxy.new @io
|
35
|
+
proxy.wait_until(0.1) { true }.should == true
|
35
36
|
end
|
36
37
|
|
37
38
|
it "should timeout if wait_while takes too long" do
|
38
|
-
|
39
|
-
proxy = Culerity::RemoteBrowserProxy.new io
|
39
|
+
proxy = Culerity::RemoteBrowserProxy.new @io
|
40
40
|
lambda {
|
41
|
-
proxy.wait_while(1) { true }
|
41
|
+
proxy.wait_while(0.1) { true }
|
42
42
|
}.should raise_error(Timeout::Error)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should return successfully when wait_while returns !true" do
|
46
|
-
|
47
|
-
proxy
|
48
|
-
proxy.wait_while(1) { false }.should == true
|
46
|
+
proxy = Culerity::RemoteBrowserProxy.new @io
|
47
|
+
proxy.wait_while(0.1) { false }.should == true
|
49
48
|
end
|
50
|
-
|
51
|
-
|
49
|
+
|
50
|
+
it "should accept all javascript confirmation dialogs" do
|
51
|
+
proxy = Culerity::RemoteBrowserProxy.new @io
|
52
|
+
|
53
|
+
proxy.should_receive(:send_remote).with(:add_listener, :confirm).and_return(true)
|
54
|
+
proxy.should_receive(:send_remote).with(:goto, "http://example.com").and_return(true)
|
55
|
+
proxy.should_receive(:send_remote).with(:remove_listener, :confirm).and_return(true)
|
56
|
+
|
57
|
+
proxy.confirm(true) do
|
58
|
+
proxy.goto "http://example.com"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -1,13 +1,45 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
3
|
describe Culerity::RemoteObjectProxy do
|
4
|
+
describe "block_to_string method" do
|
5
|
+
it "should return block result when result is lambda string" do
|
6
|
+
proxy = Culerity::RemoteObjectProxy.new nil, nil
|
7
|
+
block = lambda { "lambda { true}" }
|
8
|
+
proxy.send(:block_to_string, &block).should == "lambda { true}"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return lambda string when block result isn't a lambda string" do
|
12
|
+
proxy = Culerity::RemoteObjectProxy.new nil, nil
|
13
|
+
[true, false, "blah", 5].each do |var|
|
14
|
+
block = lambda { var }
|
15
|
+
proxy.send(:block_to_string, &block).should == "lambda { #{var} }"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
4
20
|
it "should send the serialized method call to the output" do
|
5
21
|
io = stub 'io', :gets => '[:return]'
|
6
|
-
io.should_receive(:<<).with(
|
22
|
+
io.should_receive(:<<).with(%Q{[345, "goto", "/homepage"]\n})
|
7
23
|
proxy = Culerity::RemoteObjectProxy.new 345, io
|
8
24
|
proxy.goto '/homepage'
|
9
25
|
end
|
10
26
|
|
27
|
+
it "should send the serialized method call with argument plus block to the output" do
|
28
|
+
io = stub 'io', :gets => "[:return]"
|
29
|
+
io.should_receive(:<<).with(%Q{[345, "method", true, lambda { true }]\n})
|
30
|
+
proxy = Culerity::RemoteObjectProxy.new 345, io
|
31
|
+
|
32
|
+
proxy.send_remote(:method, true) { "lambda { true }" }
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should send the serialized method call without argument plus block to the output" do
|
36
|
+
io = stub 'io', :gets => "[:return]"
|
37
|
+
io.should_receive(:<<).with(%Q{[345, "method", lambda { true }]\n})
|
38
|
+
proxy = Culerity::RemoteObjectProxy.new 345, io
|
39
|
+
|
40
|
+
proxy.send_remote(:method) { "lambda { true }" }
|
41
|
+
end
|
42
|
+
|
11
43
|
it "should return the deserialized return value" do
|
12
44
|
io = stub 'io', :gets => "[:return, :okay]\n", :<< => nil
|
13
45
|
proxy = Culerity::RemoteObjectProxy.new 345, io
|
@@ -15,7 +47,7 @@ describe Culerity::RemoteObjectProxy do
|
|
15
47
|
end
|
16
48
|
|
17
49
|
it "should raise the received exception" do
|
18
|
-
io = stub 'io', :gets =>
|
50
|
+
io = stub 'io', :gets => %Q{[:exception, "RuntimeError", "test exception", []]}, :<< => nil
|
19
51
|
proxy = Culerity::RemoteObjectProxy.new 345, io
|
20
52
|
lambda {
|
21
53
|
proxy.goto '/home'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: langalex-culerity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Lang
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-16 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -47,20 +47,35 @@ files:
|
|
47
47
|
- Rakefile
|
48
48
|
- VERSION.yml
|
49
49
|
- culerity.gemspec
|
50
|
-
-
|
51
|
-
-
|
50
|
+
- features/fixtures/sample_feature
|
51
|
+
- features/installing_culerity.feature
|
52
|
+
- features/step_definitions/common_steps.rb
|
53
|
+
- features/step_definitions/culerity_setup_steps.rb
|
54
|
+
- features/step_definitions/rails_setup_steps.rb
|
55
|
+
- features/support/common.rb
|
56
|
+
- features/support/env.rb
|
57
|
+
- features/support/matchers.rb
|
52
58
|
- init.rb
|
53
59
|
- lib/culerity.rb
|
54
60
|
- lib/culerity/celerity_server.rb
|
55
61
|
- lib/culerity/remote_browser_proxy.rb
|
56
62
|
- lib/culerity/remote_object_proxy.rb
|
57
63
|
- rails/init.rb
|
64
|
+
- rails_generators/culerity/culerity_generator.rb
|
65
|
+
- rails_generators/culerity/templates/config/environments/culerity_continuousintegration.rb
|
66
|
+
- rails_generators/culerity/templates/config/environments/culerity_development.rb
|
67
|
+
- rails_generators/culerity/templates/features/step_definitions/common_celerity_steps.rb
|
68
|
+
- rails_generators/culerity/templates/lib/tasks/culerity.rake
|
69
|
+
- script/console
|
70
|
+
- script/destroy
|
71
|
+
- script/generate
|
58
72
|
- spec/celerity_server_spec.rb
|
59
73
|
- spec/remote_browser_proxy_spec.rb
|
60
74
|
- spec/remote_object_proxy_spec.rb
|
61
75
|
- spec/spec_helper.rb
|
62
76
|
has_rdoc: false
|
63
77
|
homepage: http://github.com/langalex/culerity
|
78
|
+
licenses:
|
64
79
|
post_install_message:
|
65
80
|
rdoc_options:
|
66
81
|
- --charset=UTF-8
|
@@ -81,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
96
|
requirements: []
|
82
97
|
|
83
98
|
rubyforge_project:
|
84
|
-
rubygems_version: 1.
|
99
|
+
rubygems_version: 1.3.5
|
85
100
|
signing_key:
|
86
101
|
specification_version: 3
|
87
102
|
summary: Culerity integrates Cucumber and Celerity in order to test your application's full stack.
|
@@ -1,20 +0,0 @@
|
|
1
|
-
class CulerityGenerator < Rails::Generator::Base
|
2
|
-
|
3
|
-
def initialize(runtime_args, runtime_options = {})
|
4
|
-
Dir.mkdir('features/step_definitions') unless File.directory?('features/step_definitions')
|
5
|
-
super
|
6
|
-
end
|
7
|
-
|
8
|
-
def manifest
|
9
|
-
record do |m|
|
10
|
-
m.template 'common_celerity.rb', 'features/step_definitions/common_celerity.rb'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
protected
|
15
|
-
|
16
|
-
def banner
|
17
|
-
"Usage: #{$0} culerity"
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|