drnic-culerity 0.2.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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ coverage
2
+ rdoc
3
+ pkg
4
+ tmp
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Alexander Lang
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,101 @@
1
+ h2. Introduction
2
+
3
+ Culerity integrates Cucumber and Celerity in order to test your application's full stack.
4
+
5
+ Culerity lets you:
6
+ * run Celerity from within Cucumber which allows you to test the full stack of your Rails (or other web) application from Database to in browser JavaScript
7
+ * run your application in any Ruby (like MRI 1.8.6) while Celerity runs in JRuby so you can still use gems/plugins that would not work with JRuby
8
+ * reuse existing Webrat-Style step definitions
9
+
10
+ h2. Getting Started
11
+
12
+ The following guide is written for a Rails application (tested with 2.2.2) but Culerity should work with any other Web Framework that is supported by Cucumber.
13
+
14
+ First download JRuby and unpack it to some location, for example $HOME/jruby. Make sure that the jruby executable is in your path. You can do this by either setting your PATH accordingly...
15
+
16
+ <pre><code> export PATH=$HOME/jruby/bin:$PATH</code></pre>
17
+
18
+ ... or by creating a symlink from your bin directory:
19
+
20
+ <pre><code> ln -s $HOME/jruby/bin/jruby /usr/bin/jruby</code></pre>
21
+
22
+ Next install the celerity gem for JRuby:
23
+
24
+ <pre><code> jruby -S gem install celerity</code></pre>
25
+
26
+ Now (assuming you have a Rails application set up already) install Culerity as a Rails Plugin:
27
+
28
+ <pre><code> cd RAILS_ROOT
29
+ git clone git://github.com/langalex/culerity.git</code></pre>
30
+
31
+ or as a gem: (definitely preferred)
32
+
33
+ <pre><code> gem install langalex-culerity --source http://gems.github.com</code></pre>
34
+
35
+ Run the RSpec, Cucumber and Culerity generators:
36
+
37
+ <pre><code>
38
+ cd RAILS_ROOT
39
+ script/generate rspec
40
+ script/generate cucumber
41
+ script/generate culerity
42
+ </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
+
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
+ NOTE: The default port for this server is 3001. You can change this in features/step_definitions/common_celerity.rb
49
+
50
+
51
+ <pre><code> script/server -p 3001 -e test
52
+ cucumber features/my_feature.feature
53
+ </code></pre>
54
+
55
+ h2. How does it work
56
+
57
+ 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.
58
+
59
+ h2. Troubleshooting
60
+
61
+ I get a broken pipe error:
62
+ * make sure JRuby is installed and in your path: running _jruby -v_ should not produce an error
63
+
64
+ I get _Connection Refused_ errors
65
+ * make sure you have started a server in the test environment that runs on port 3001
66
+
67
+ My application can't find the data I create in my steps
68
+ * make sure you have disabled transactional fixtures in your env.rb
69
+
70
+ My database is not cleared automatically between scenarios
71
+ * Rails can't clean the database because you had to disable transactional fixtures - which only work if your test process is the same as your web server process. Hence you have to clean your database manually. A quick way would be:
72
+
73
+ <pre><code>Before do
74
+ [User, .... all your models].each do |model|
75
+ mode.delete_all
76
+ end
77
+ end
78
+ </code></pre>
79
+
80
+ I want to test emails but the ActionMailer::Base.deliveries array is always empty.
81
+ * that's because the :test delivery method stores all emails in memory, but now that your test process is not the same as your rails process you don't have access to that array. install the http://github.com/ngty/action_mailer_cache_delivery plugin to access the emails in your rails process via a temporary file
82
+
83
+
84
+ h2. Links to Celerity documentation
85
+
86
+ * "How to select elements":http://celerity.rubyforge.org/yard/Celerity/Container.html
87
+ * "FAQ":http://wiki.github.com/jarib/celerity/faq
88
+ * "Tutorial":http://wiki.github.com/jarib/celerity/getting-started
89
+ * "API docs":http://celerity.rubyforge.org/yard/
90
+
91
+ h2. Links
92
+
93
+ * "cucumber":http://github.com/aslakhellesoy/cucumber/wikis
94
+ * "celerity":http://celerity.rubyforge.org
95
+ * "jruby":http://jruby.codehaus.org
96
+ * "rspec":http://rspec.info
97
+ * "htmlunit":http://htmlunit.sourceforge.net/
98
+
99
+ h2. Contact
100
+
101
+ Written 2009 by Alexander Lang, contact alex[at]upstream-berlin.com or http://github.com/langalex, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ # require 'rcov/rcovtask'
5
+
6
+ begin
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |s|
9
+ s.name = "culerity"
10
+ s.summary = %Q{Culerity integrates Cucumber and Celerity in order to test your application's full stack.}
11
+ s.email = "alex@upstream-berlin.com"
12
+ s.homepage = "http://github.com/langalex/culerity"
13
+ s.description = "Culerity integrates Cucumber and Celerity in order to test your application's full stack."
14
+ s.authors = ["Alexander Lang"]
15
+ s.add_dependency 'cucumber'
16
+ s.add_dependency 'rspec'
17
+ end
18
+ rescue LoadError
19
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
20
+ end
21
+
22
+ Rake::TestTask.new do |t|
23
+ t.libs << 'lib'
24
+ t.pattern = 'spec/**/*_spec.rb'
25
+ t.verbose = false
26
+ end
27
+
28
+ Rake::RDocTask.new do |rdoc|
29
+ rdoc.rdoc_dir = 'rdoc'
30
+ rdoc.title = 'Culerity'
31
+ rdoc.options << '--line-numbers' << '--inline-source'
32
+ rdoc.rdoc_files.include('README*')
33
+ rdoc.rdoc_files.include('lib/**/*.rb')
34
+ end
35
+
36
+ # Rcov::RcovTask.new do |t|
37
+ # t.libs << 'spec'
38
+ # t.test_files = FileList['spec/**/*_spec.rb']
39
+ # t.verbose = true
40
+ # end
41
+
42
+ task :default => :test
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 2
4
+ :patch: 1
data/culerity.gemspec ADDED
@@ -0,0 +1,79 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{culerity}
8
+ s.version = "0.2.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Alexander Lang"]
12
+ s.date = %q{2009-08-15}
13
+ s.description = %q{Culerity integrates Cucumber and Celerity in order to test your application's full stack.}
14
+ s.email = %q{alex@upstream-berlin.com}
15
+ s.extra_rdoc_files = [
16
+ "README.textile"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README.textile",
22
+ "Rakefile",
23
+ "VERSION.yml",
24
+ "culerity.gemspec",
25
+ "features/fixtures/sample_feature",
26
+ "features/installing_culerity.feature",
27
+ "features/step_definitions/common_steps.rb",
28
+ "features/step_definitions/culerity_setup_steps.rb",
29
+ "features/step_definitions/rails_setup_steps.rb",
30
+ "features/support/common.rb",
31
+ "features/support/env.rb",
32
+ "features/support/matchers.rb",
33
+ "init.rb",
34
+ "lib/culerity.rb",
35
+ "lib/culerity/celerity_server.rb",
36
+ "lib/culerity/remote_browser_proxy.rb",
37
+ "lib/culerity/remote_object_proxy.rb",
38
+ "rails/init.rb",
39
+ "rails_generators/culerity/culerity_generator.rb",
40
+ "rails_generators/culerity/templates/config/environments/culerity_continuousintegration.rb",
41
+ "rails_generators/culerity/templates/config/environments/culerity_development.rb",
42
+ "rails_generators/culerity/templates/features/step_definitions/common_celerity_steps.rb",
43
+ "rails_generators/culerity/templates/lib/tasks/culerity.rake",
44
+ "script/console",
45
+ "script/destroy",
46
+ "script/generate",
47
+ "spec/celerity_server_spec.rb",
48
+ "spec/remote_browser_proxy_spec.rb",
49
+ "spec/remote_object_proxy_spec.rb",
50
+ "spec/spec_helper.rb"
51
+ ]
52
+ s.homepage = %q{http://github.com/langalex/culerity}
53
+ s.rdoc_options = ["--charset=UTF-8"]
54
+ s.require_paths = ["lib"]
55
+ s.rubygems_version = %q{1.3.5}
56
+ s.summary = %q{Culerity integrates Cucumber and Celerity in order to test your application's full stack.}
57
+ s.test_files = [
58
+ "spec/celerity_server_spec.rb",
59
+ "spec/remote_browser_proxy_spec.rb",
60
+ "spec/remote_object_proxy_spec.rb",
61
+ "spec/spec_helper.rb"
62
+ ]
63
+
64
+ if s.respond_to? :specification_version then
65
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
66
+ s.specification_version = 3
67
+
68
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
69
+ s.add_runtime_dependency(%q<cucumber>, [">= 0"])
70
+ s.add_runtime_dependency(%q<rspec>, [">= 0"])
71
+ else
72
+ s.add_dependency(%q<cucumber>, [">= 0"])
73
+ s.add_dependency(%q<rspec>, [">= 0"])
74
+ end
75
+ else
76
+ s.add_dependency(%q<cucumber>, [">= 0"])
77
+ s.add_dependency(%q<rspec>, [">= 0"])
78
+ end
79
+ end
@@ -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,41 @@
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
+ Scenario: Install culerity into a Rails app and check it works
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
+ Then file "features/step_definitions/common_celerity_steps.rb" is created
15
+ Then file "config/environments/culerity_development.rb" is created
16
+ Then file "config/environments/culerity_continuousintegration.rb" is created
17
+
18
+ And I run executable "cucumber" with arguments "features/"
19
+ Then I should see "0 scenarios"
20
+ And I should see "0 steps"
21
+
22
+ Given I invoke task "rake culerity:rails:start"
23
+
24
+ When I add a feature file to test Rails index.html default file
25
+ And I run executable "cucumber" with arguments "features/"
26
+ Then I should see "1 scenario"
27
+ And I should see "5 steps (5 passed)"
28
+
29
+ Scenario: Install culerity and test the rails start + stop tasks
30
+ Given a Rails app
31
+ And I run executable "script/generate" with arguments "cucumber"
32
+ And I delete file "features/step_definitions/webrat_steps.rb"
33
+ And I copy the project generators into "vendor/generators"
34
+ And I invoke task "rake db:migrate"
35
+ When I run executable "script/generate" with arguments "culerity"
36
+ And I invoke task "rake culerity:rails:start"
37
+ Then file "tmp/culerity_rails_server.pid" is created
38
+ And I invoke task "rake culerity:rails:stop"
39
+ Then file "tmp/culerity_rails_server.pid" is not created
40
+
41
+
@@ -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,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/common_celerity_steps.rb')
5
+ end
6
+ end
7
+
@@ -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)
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'rails/init'
@@ -0,0 +1,65 @@
1
+ require 'rubygems'
2
+ require 'celerity'
3
+
4
+
5
+ module Culerity
6
+ class CelerityServer
7
+
8
+ def initialize(_in, _out)
9
+ @proxies = {}
10
+ @browser_options = {}
11
+
12
+ while(true)
13
+ call = eval _in.gets.to_s.strip
14
+ return if call == ["_exit_"]
15
+ unless call.nil?
16
+ begin
17
+ # check if last arg is a block
18
+ if call.last.is_a?(Proc)
19
+ # pass as &call[-1]
20
+ result = target(call.first).send call[1], *call[2..-2], &call[-1]
21
+ else
22
+ # just call with args as normal
23
+ result = target(call.first).send call[1], *call[2..-1]
24
+ end
25
+ _out << "[:return, #{proxify result}]\n"
26
+ rescue => e
27
+ _out << "[:exception, \"#{e.class.name}\", #{e.message.inspect}, #{e.backtrace.inspect}]\n"
28
+ end
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ private
35
+
36
+ def configure_browser(options)
37
+ @browser_options = options
38
+ end
39
+
40
+ def browser
41
+ @browser ||= Celerity::Browser.new @browser_options || {}
42
+ end
43
+
44
+ def target(object_id)
45
+ if object_id == 'browser'
46
+ browser
47
+ elsif object_id == 'celerity'
48
+ self
49
+ else
50
+ @proxies[object_id]
51
+ end
52
+ end
53
+
54
+ def proxify(result, in_array = false)
55
+ if result.is_a?(Array)
56
+ result.map {|x| proxify(x, true) }.inspect
57
+ elsif [String, TrueClass, FalseClass, Fixnum, Float, NilClass].include?(result.class)
58
+ in_array ? result : result.inspect
59
+ else
60
+ @proxies[result.object_id] = result
61
+ "Culerity::RemoteObjectProxy.new(#{result.object_id}, @io)"
62
+ end
63
+ end
64
+ end
65
+ end