cucumba 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ .yardoc/*
2
+ .spec/*
3
+ pkg/*
4
+ *.gem
5
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'rake', '0.8.7'
7
+ gem 'yard', '>= 0.6.1'
8
+ gem 'rails', '2.3.8'
9
+ gem 'sqlite3-ruby','1.3.1'
10
+ gem 'rspec', '1.3.0'
11
+ gem 'bluecloth'
12
+ end
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cucumba (0.0.6)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ actionmailer (2.3.8)
10
+ actionpack (= 2.3.8)
11
+ actionpack (2.3.8)
12
+ activesupport (= 2.3.8)
13
+ rack (~> 1.1.0)
14
+ activerecord (2.3.8)
15
+ activesupport (= 2.3.8)
16
+ activeresource (2.3.8)
17
+ activesupport (= 2.3.8)
18
+ activesupport (2.3.8)
19
+ bluecloth (2.0.9)
20
+ rack (1.1.0)
21
+ rails (2.3.8)
22
+ actionmailer (= 2.3.8)
23
+ actionpack (= 2.3.8)
24
+ activerecord (= 2.3.8)
25
+ activeresource (= 2.3.8)
26
+ activesupport (= 2.3.8)
27
+ rake (>= 0.8.3)
28
+ rake (0.8.7)
29
+ rspec (1.3.0)
30
+ sqlite3-ruby (1.3.1)
31
+ yard (0.6.1)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bluecloth
38
+ cucumba!
39
+ rails (= 2.3.8)
40
+ rake (= 0.8.7)
41
+ rspec (= 1.3.0)
42
+ sqlite3-ruby (= 1.3.1)
43
+ yard (>= 0.6.1)
data/History.md CHANGED
@@ -1,8 +1,19 @@
1
- 0.0.6 (ureleased)
2
-
3
1
  * TODO
4
2
  * invoking rake tasks
5
- * optimize testing
3
+ * showing rails load error(add bad envoronment and do there mistage(concat "some string"))
4
+ * routes(Cucumba[:main].routes.root\_url)
5
+ * hadling privileged ports(80) with sudo,and fix url method for it
6
+ * ability to properly run miltiple servers
7
+ * add loadign rails builtin controller
8
+ * add drb\_port option to cucumba.yml
9
+ * add drb\_ip to config file(drb ip to run on)
10
+
11
+ 0.0.6 (05.10.2010)
12
+
13
+ * starting to use bundler
14
+ * optimized testing
15
+ * fixed starting drb server(it should run on 127.0.0.1) and not on host described in config/cucumba.yml
16
+ * refactored internal stuff(Cucumba::Rails => Cucumba::Railz, Cucumba:Railz::Model => Cucumba::Railz::Klass)
6
17
 
7
18
  0.0.5 (04.10.2010)
8
19
  ------------------
data/Rakefile CHANGED
@@ -1,33 +1,5 @@
1
- require 'rubygems'
2
- gem 'hoe', '>= 2.1.0'
3
- require 'hoe'
4
- require 'fileutils'
5
- require './lib/cucumba'
6
-
7
- Hoe.plugin :newgem
8
- Hoe.plugin :website
9
-
10
- # Generate all the Rake tasks
11
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
12
- $hoe = Hoe.spec 'cucumba' do
13
- self.developer 'kucaahbe', 'kucaahbe@ukr.net'
14
- self.post_install_message = 'PostInstall.txt'
15
- self.rubyforge_name = self.name
16
- # self.extra_deps = [['activesupport','>= 2.0.2']]
17
- self.extra_dev_deps = [
18
- ['yard', '>= 0.6.1'],
19
- ['bluecloth', '2.0.9'],
20
- ['rails', '2.3.8'],
21
- ['sqlite3-ruby','1.3.1'],
22
- ['rspec', '1.3.0']
23
- ]
24
- self.history_file = 'History.md'
25
- self.readme_file = 'README.rdoc'
26
- end
27
-
28
- require 'newgem/tasks'
29
- Dir['tasks/**/*.rake'].each { |t| load t }
30
-
31
- remove_task :default
32
- remove_task :spec
33
- task :default => ['spec:config', 'spec:rails']
1
+ require 'bundler'
2
+ Bundler.setup(:development)
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ Dir['tasks/**/*.rake'].each { |t| load t }
@@ -1,52 +1,24 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "cucumba/version"
2
4
 
3
5
  Gem::Specification.new do |s|
4
- s.name = %q{cucumba}
5
- s.version = "0.0.5"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["kucaahbe"]
9
- s.date = %q{2010-10-04}
10
- s.description = %q{If you develop more than one rails applications
11
- that communicate with each other and you need to test them
12
- with something like capybara and also whant to communicate with database -
13
- this gem will help you}
14
- s.email = ["kucaahbe@ukr.net"]
15
- s.extra_rdoc_files = ["Manifest.txt", "PostInstall.txt", "website/index.txt"]
16
- s.files = ["History.md", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "config/website.yml.sample", "cucumba.gemspec", "generators/cucumba/USAGE", "generators/cucumba/cucumba_generator.rb", "generators/cucumba/templates/config.yml", "generators/cucumba/templates/cucumba", "lib/cucumba.rb", "lib/cucumba/drb.rb", "lib/cucumba/rails.rb", "lib/cucumba/rails/model.rb", "lib/cucumba/rails/runner.rb", "lib/cucumba/server.rb", "script/console", "script/destroy", "script/generate", "script/txt2html", "spec/cucumba_configuration_spec.rb", "spec/cucumba_spec_rails.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/support/sample_app/README", "spec/support/sample_app/Rakefile", "spec/support/sample_app/app/controllers/application_controller.rb", "spec/support/sample_app/app/controllers/users_controller.rb", "spec/support/sample_app/app/helpers/application_helper.rb", "spec/support/sample_app/app/helpers/users_helper.rb", "spec/support/sample_app/app/models/user.rb", "spec/support/sample_app/app/views/layouts/users.html.erb", "spec/support/sample_app/app/views/users/edit.html.erb", "spec/support/sample_app/app/views/users/index.html.erb", "spec/support/sample_app/app/views/users/new.html.erb", "spec/support/sample_app/app/views/users/show.html.erb", "spec/support/sample_app/config/boot.rb", "spec/support/sample_app/config/database.yml", "spec/support/sample_app/config/environment.rb", "spec/support/sample_app/config/environments/development.rb", "spec/support/sample_app/config/environments/production.rb", "spec/support/sample_app/config/environments/test.rb", "spec/support/sample_app/config/initializers/cookie_verification_secret.rb", "spec/support/sample_app/config/initializers/new_rails_defaults.rb", "spec/support/sample_app/config/initializers/session_store.rb", "spec/support/sample_app/config/routes.rb", "spec/support/sample_app/db/schema.rb", "spec/support/sample_app/public/404.html", "spec/support/sample_app/public/422.html", "spec/support/sample_app/public/500.html", "spec/support/sample_app/public/favicon.ico", "spec/support/sample_app/public/images/rails.png", "spec/support/sample_app/public/index.html", "spec/support/sample_app/public/javascripts/application.js", "spec/support/sample_app/public/javascripts/controls.js", "spec/support/sample_app/public/javascripts/dragdrop.js", "spec/support/sample_app/public/javascripts/effects.js", "spec/support/sample_app/public/javascripts/prototype.js", "spec/support/sample_app/public/robots.txt", "spec/support/sample_app/public/stylesheets/scaffold.css", "spec/support/sample_app/script/about", "spec/support/sample_app/script/console", "spec/support/sample_app/script/dbconsole", "spec/support/sample_app/script/destroy", "spec/support/sample_app/script/generate", "spec/support/sample_app/script/performance/benchmarker", "spec/support/sample_app/script/performance/profiler", "spec/support/sample_app/script/plugin", "spec/support/sample_app/script/runner", "spec/support/sample_app/script/server", "spec/support/sample_app_run.sh", "tasks/rspec.rake", "tasks/yard.rake", "website/index.html", "website/index.txt", "website/javascripts/rounded_corners_lite.inc.js", "website/stylesheets/screen.css", "website/template.html.erb"]
17
- s.homepage = %q{http://github.com/hxcoding/cucumba}
6
+ s.name = "cucumba"
7
+ s.version = Cucumba::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["kucaahbe"]
10
+ s.email = ["kucaahbe@ukr.net"]
11
+ s.homepage = "http://rubygems.org/gems/cucumba"
12
+ s.summary = %q{If you develop more than one rails applications that communicate with each other and you need to test them with something like capybara and also whant to communicate with database - this gem will help you}
13
+ s.description = s.summary
14
+ s.homepage = %q{http://github.com/hxcoding/cucumba}
18
15
  s.post_install_message = %q{PostInstall.txt}
19
- s.rdoc_options = ["--main", "README.rdoc"]
20
- s.require_paths = ["lib"]
21
- s.rubyforge_project = %q{cucumba}
22
- s.rubygems_version = %q{1.3.7}
23
- s.summary = %q{If you develop more than one rails applications that communicate with each other and you need to test them with something like capybara and also whant to communicate with database - this gem will help you}
24
16
 
25
- if s.respond_to? :specification_version then
26
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
27
- s.specification_version = 3
28
17
 
29
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
30
- s.add_development_dependency(%q<yard>, [">= 0.6.1"])
31
- s.add_development_dependency(%q<bluecloth>, ["= 2.0.9"])
32
- s.add_development_dependency(%q<rails>, ["= 2.3.8"])
33
- s.add_development_dependency(%q<sqlite3-ruby>, ["= 1.3.1"])
34
- s.add_development_dependency(%q<rspec>, ["= 1.3.0"])
35
- s.add_development_dependency(%q<hoe>, [">= 2.6.2"])
36
- else
37
- s.add_dependency(%q<yard>, [">= 0.6.1"])
38
- s.add_dependency(%q<bluecloth>, ["= 2.0.9"])
39
- s.add_dependency(%q<rails>, ["= 2.3.8"])
40
- s.add_dependency(%q<sqlite3-ruby>, ["= 1.3.1"])
41
- s.add_dependency(%q<rspec>, ["= 1.3.0"])
42
- s.add_dependency(%q<hoe>, [">= 2.6.2"])
43
- end
44
- else
45
- s.add_dependency(%q<yard>, [">= 0.6.1"])
46
- s.add_dependency(%q<bluecloth>, ["= 2.0.9"])
47
- s.add_dependency(%q<rails>, ["= 2.3.8"])
48
- s.add_dependency(%q<sqlite3-ruby>, ["= 1.3.1"])
49
- s.add_dependency(%q<rspec>, ["= 1.3.0"])
50
- s.add_dependency(%q<hoe>, [">= 2.6.2"])
51
- end
18
+ s.rubyforge_project = "cucumba"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
52
24
  end
@@ -2,10 +2,9 @@ lib = File.expand_path(File.join(File.dirname(__FILE__),'../lib'))
2
2
  $:.unshift(lib) unless $:.include?(lib)
3
3
 
4
4
  require 'yaml'
5
- require 'cucumba/rails'
5
+ require 'cucumba/railz'
6
6
 
7
7
  module Cucumba
8
- VERSION = '0.0.5'
9
8
 
10
9
  class ConfigNotFound < StandardError
11
10
  end
@@ -23,22 +22,22 @@ module Cucumba
23
22
  def self.[] server_name
24
23
  server_name = server_name.to_s
25
24
  if server_name == "_self_"
26
- Cucumba::Rails.new(config.first)
25
+ Cucumba::Railz.new(config.first)
27
26
  else
28
- Cucumba::Rails.new(config_for(server_name))
27
+ Cucumba::Railz.new(config_for(server_name))
29
28
  end
30
29
  end
31
30
 
32
31
  private
33
32
 
34
- def self.config_for(server_name)
33
+ def self.config_for server_name
35
34
  config.each do |server_config|
36
35
  if server_config[:name]==server_name
37
36
  return server_config
38
37
  break
39
38
  end
40
39
  end
41
- raise Cucumba::Rails::ServerNotFound, "server with '#{server_name}' not described in config file"
40
+ raise Cucumba::Railz::ServerNotFound, "server with name '#{server_name}' not described in config file"
42
41
  rescue Errno::ENOENT # yml file not found
43
42
  raise ConfigNotFound, "config not found, run 'cucumba' generator"
44
43
  end
@@ -4,17 +4,17 @@ require 'drb'
4
4
  module Cucumba
5
5
  class Drb
6
6
  class Server
7
- def has_model?(model)
8
- Object.const_defined?(model.to_s.classify)
7
+ def has_constant?(const)
8
+ Object.const_defined?(const.to_s.classify)
9
9
  end
10
10
 
11
- def model_has_method?(model,method)
12
- Object.const_get(model).respond_to?(method)
11
+ def constant_has_method?(const,method)
12
+ Object.const_get(const).respond_to?(method)
13
13
  end
14
14
 
15
- def invoke_method_on_model(model,method,*args)
16
- logger.info "Processing #{model}.#{method.to_s} (for TODO_IP at #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}) [DRb]"
17
- Object.const_get(model).method(method).call(*args.first)
15
+ def invoke_method_on_constant(const,method,*args)
16
+ logger.info "Processing #{const}.#{method.to_s} (for TODO_IP at #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}) [DRb]"
17
+ Object.const_get(const).method(method).call(*args.first)
18
18
  rescue Exception => e
19
19
  handle_exception(e)
20
20
  raise RuntimeError, "#{e.class.to_s} #{e.message}"
@@ -47,6 +47,7 @@ module Cucumba
47
47
  end
48
48
 
49
49
  begin
50
- DRb.start_service(Cucumba[:_self_].drb_url, Cucumba::Drb::Server.new) if Cucumba[:_self_].run?
50
+ DRb.start_service("druby://127.0.0.1:#{Cucumba[:_self_].drb_port}", Cucumba::Drb::Server.new) if Cucumba[:_self_].run?
51
51
  rescue Errno::EADDRINUSE
52
+ puts "=> Cucumba DRb server not starting, port #{Cucumba[:_self_].drb_port} already in use"
52
53
  end
@@ -1,9 +1,13 @@
1
1
  require 'drb'
2
- require 'cucumba/rails/model'
2
+ require 'cucumba/railz/klass'
3
3
 
4
4
  module Cucumba
5
- # Cucumba rails client
6
- class Rails
5
+ # This class represents you rails application
6
+ # You get it when through
7
+ #
8
+ # Cucumba[:main]
9
+ # for instance
10
+ class Railz
7
11
 
8
12
  class ServerNotFound < Exception
9
13
  end
@@ -36,6 +40,9 @@ module Cucumba
36
40
  'druby://'+@host+':'+@drb_port.to_s
37
41
  end
38
42
 
43
+ #--
44
+ # TODO move to routes
45
+ #++
39
46
  def rails_root
40
47
  @path
41
48
  end
@@ -44,10 +51,10 @@ module Cucumba
44
51
  @run
45
52
  end
46
53
 
47
- def model(model_name)
48
- Model.new(model_name,@server)
54
+ def class(class_name)
55
+ Klass.new(class_name,@server)
49
56
  end
50
- alias :m :model
57
+ alias :c :class
51
58
 
52
59
  def execute(code)
53
60
  @server.execute(code)
@@ -0,0 +1,27 @@
1
+ module Cucumba
2
+ class Railz
3
+ # This class represents some object in rails application
4
+ class Klass
5
+
6
+ class NotFoundError < Exception
7
+ end
8
+
9
+ def initialize(constant,server)
10
+ @server = server
11
+ if @server.has_constant?(constant)
12
+ @constant = constant
13
+ else
14
+ raise NotFoundError
15
+ end
16
+ end
17
+
18
+ def method_missing(method,*args)
19
+ if @server.constant_has_method?(@constant,method)
20
+ @server.invoke_method_on_constant(@constant,method,args)
21
+ else
22
+ super
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -3,7 +3,7 @@ require 'net/http'
3
3
 
4
4
  module Cucumba
5
5
 
6
- class Rails
6
+ class Railz
7
7
 
8
8
  def rails_start!
9
9
  if run?
@@ -1,7 +1,7 @@
1
1
  lib = File.expand_path(File.join(File.dirname(__FILE__),'..'))
2
2
  $:.unshift(lib) unless $:.include?(lib)
3
3
 
4
- require 'cucumba/rails/runner'
4
+ require 'cucumba/railz/runner'
5
5
 
6
6
  Cucumba.servers_start!
7
7
  trap(:INT) do
@@ -0,0 +1,3 @@
1
+ module Cucumba
2
+ VERSION = "0.0.6"
3
+ end
@@ -38,7 +38,7 @@ describe "Cucumba configuration" do
38
38
  [:name, "name"].each do |server|
39
39
  client = Cucumba[server]
40
40
 
41
- client.should be_instance_of(Cucumba::Rails)
41
+ client.should be_instance_of(Cucumba::Railz)
42
42
  client.host.should == 'some.host'
43
43
  client.port.should == 4321
44
44
  client.rails_root == '/path/to/rails/app'
@@ -76,12 +76,13 @@ describe "Cucumba configuration" do
76
76
  it "should raise exception if server not found in config" do
77
77
  Rails.should_receive(:root)
78
78
  YAML.should_receive(:load_file).once.and_return(@good_config)
79
- lambda { Cucumba[:wrong] }.should raise_exception(Cucumba::Rails::ServerNotFound)
79
+ lambda { Cucumba[:wrong] }.should raise_exception(Cucumba::Railz::ServerNotFound)
80
80
  end
81
81
 
82
82
  end
83
83
 
84
84
  after :all do
85
+ force_cucumba_reload_config
85
86
  begin
86
87
  remove_fake_rails_module
87
88
  rescue NameError
@@ -1,32 +1,40 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- ENV["RAILS_ENV"] ||= 'test'
4
- require File.expand_path(File.dirname(__FILE__) + '/support/sample_app/config/environment')
5
-
6
3
  describe "Cucumba[:server]" do
7
4
 
8
- it "should return instance of Cucumba::Rails" do
9
- Cucumba[:test].should be_instance_of(Cucumba::Rails)
5
+ before :all do
6
+ @pwd = Dir.pwd; Dir.chdir('spec/support/sample_app')
7
+
8
+ require 'active_record'
9
+
10
+ active_record_config = YAML.load_file('config/database.yml')
11
+
12
+ ActiveRecord::Base.establish_connection(active_record_config["test"])
13
+ Dir[File.join('app/models/*.rb')].each { |model| load model }
10
14
  end
11
15
 
12
- context "#model" do
16
+ it "should return instance of Cucumba::Railz" do
17
+ Cucumba[:test].should be_instance_of(Cucumba::Railz)
18
+ end
19
+
20
+ context "#class" do
13
21
 
14
- it "should return instace of Cucumba::Rails::Model" do
15
- [ Cucumba[:test].model("User"), Cucumba[:test].m("User"), Cucumba[:test].model(:User), Cucumba[:test].m(:User) ].each do |model|
16
- model.should be_instance_of(Cucumba::Rails::Model)
22
+ it "should return instace of Cucumba::Railz::Klass" do
23
+ [ Cucumba[:test].class("User"), Cucumba[:test].c("User"), Cucumba[:test].class(:User), Cucumba[:test].c(:User) ].each do |object|
24
+ object.should be_instance_of(Cucumba::Railz::Klass)
17
25
  end
18
26
  end
19
27
 
20
28
  it "should invoke existing methods" do
21
29
  users_count_was = User.all.count
22
- Cucumba[:test].m("User").create!(:name => 'test user', :password => 'secret')
30
+ Cucumba[:test].c("User").create!(:name => 'test user', :password => 'secret')
23
31
  (User.all.count - users_count_was).should == 1
24
32
  User.last.name.should == 'test user'
25
33
  User.last.password.should == 'secret'
26
34
  end
27
35
 
28
36
  it "should invoke method without arguments" do
29
- Cucumba[:test].m(:User).columns
37
+ Cucumba[:test].c(:User).columns
30
38
  end
31
39
 
32
40
  it "should eval code in server side" do
@@ -40,20 +48,24 @@ describe "Cucumba[:server]" do
40
48
  end
41
49
 
42
50
  it "should invoke this method" do
43
- Cucumba[:test].m(:User).method_with_args(:name, :first => 'bla', :last => 'alb')
51
+ Cucumba[:test].c(:User).method_with_args(:name, :first => 'bla', :last => 'alb')
44
52
  end
45
53
 
46
- it "should raise exception if model does not exists" do
47
- lambda { Cucumba[:test].m("Unknown") }.should raise_exception(Cucumba::Rails::Model::NotFoundError)
54
+ it "should raise exception if class does not exists" do
55
+ lambda { Cucumba[:test].c("Unknown") }.should raise_exception(Cucumba::Railz::Klass::NotFoundError)
48
56
  end
49
57
 
50
58
  it "should raise exception if model's method does not exists" do
51
- lambda { Cucumba[:test].m(:User).blabla }.should raise_exception(NoMethodError)
59
+ lambda { Cucumba[:test].c(:User).blabla }.should raise_exception(NoMethodError)
52
60
  end
53
61
 
54
62
  it "should raise exception if exception appears on server" do
55
- lambda { Cucumba[:test].m(:User).create!(:password => 'secret') }.should raise_exception(RuntimeError,"ActiveRecord::RecordInvalid Validation failed: Name can't be blank")
63
+ lambda { Cucumba[:test].c(:User).create!(:password => 'secret') }.should raise_exception(RuntimeError,"ActiveRecord::RecordInvalid Validation failed: Name can't be blank")
56
64
  end
57
65
 
58
66
  end
67
+
68
+ after :all do
69
+ Dir.chdir @pwd
70
+ end
59
71
  end