From 828857f88ebb3045ecf27bf8ab659db6f3a9d136 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Mon, 29 Dec 2008 00:47:02 -0500 Subject: [PATCH 1/5] Bumping nokogiri depenency version --- Rakefile | 2 +- webrat.gemspec | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Rakefile b/Rakefile index 93581c2..44bd364 100644 --- a/Rakefile +++ b/Rakefile @@ -28,7 +28,7 @@ spec = Gem::Specification.new do |s| s.extra_rdoc_files = %w(README.rdoc MIT-LICENSE.txt) # Dependencies - s.add_dependency "nokogiri", ">= 1.0.6" + s.add_dependency "nokogiri", ">= 1.1.0" s.rubyforge_project = "webrat" end diff --git a/webrat.gemspec b/webrat.gemspec index 5362361..2988c6d 100644 --- a/webrat.gemspec +++ b/webrat.gemspec @@ -4,11 +4,11 @@ Gem::Specification.new do |s| s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Bryan Helmkamp"] - s.date = %q{2008-12-25} + s.date = %q{2008-12-29} s.description = %q{Webrat. Ruby Acceptance Testing for Web applications} s.email = %q{bryan@brynary.com} s.extra_rdoc_files = ["README.rdoc", "MIT-LICENSE.txt"] - s.files = ["History.txt", "install.rb", "MIT-LICENSE.txt", "README.rdoc", "Rakefile", "lib/webrat", "lib/webrat/core", "lib/webrat/core/configuration.rb", "lib/webrat/core/elements", "lib/webrat/core/elements/area.rb", "lib/webrat/core/elements/element.rb", "lib/webrat/core/elements/field.rb", "lib/webrat/core/elements/form.rb", "lib/webrat/core/elements/label.rb", "lib/webrat/core/elements/link.rb", "lib/webrat/core/elements/select_option.rb", "lib/webrat/core/locators", "lib/webrat/core/locators/area_locator.rb", "lib/webrat/core/locators/button_locator.rb", "lib/webrat/core/locators/field_by_id_locator.rb", "lib/webrat/core/locators/field_labeled_locator.rb", "lib/webrat/core/locators/field_locator.rb", "lib/webrat/core/locators/field_named_locator.rb", "lib/webrat/core/locators/form_locator.rb", "lib/webrat/core/locators/label_locator.rb", "lib/webrat/core/locators/link_locator.rb", "lib/webrat/core/locators/locator.rb", "lib/webrat/core/locators/select_option_locator.rb", "lib/webrat/core/locators.rb", "lib/webrat/core/logging.rb", "lib/webrat/core/matchers", "lib/webrat/core/matchers/have_content.rb", "lib/webrat/core/matchers/have_selector.rb", "lib/webrat/core/matchers/have_tag.rb", "lib/webrat/core/matchers/have_xpath.rb", "lib/webrat/core/matchers.rb", "lib/webrat/core/methods.rb", "lib/webrat/core/mime.rb", "lib/webrat/core/save_and_open_page.rb", "lib/webrat/core/scope.rb", "lib/webrat/core/session.rb", "lib/webrat/core/xml", "lib/webrat/core/xml/hpricot.rb", "lib/webrat/core/xml/nokogiri.rb", "lib/webrat/core/xml/rexml.rb", "lib/webrat/core/xml.rb", "lib/webrat/core.rb", "lib/webrat/core_extensions", "lib/webrat/core_extensions/blank.rb", "lib/webrat/core_extensions/deprecate.rb", "lib/webrat/core_extensions/detect_mapped.rb", "lib/webrat/core_extensions/hash_with_indifferent_access.rb", "lib/webrat/core_extensions/meta_class.rb", "lib/webrat/core_extensions/nil_to_param.rb", "lib/webrat/mechanize.rb", "lib/webrat/merb.rb", "lib/webrat/rack.rb", "lib/webrat/rails", "lib/webrat/rails/redirect_actions.rb", "lib/webrat/rails.rb", "lib/webrat/rspec-rails.rb", "lib/webrat/selenium", "lib/webrat/selenium/location_strategy_javascript", "lib/webrat/selenium/location_strategy_javascript/button.js", "lib/webrat/selenium/location_strategy_javascript/label.js", "lib/webrat/selenium/location_strategy_javascript/webrat.js", "lib/webrat/selenium/location_strategy_javascript/webratlink.js", "lib/webrat/selenium/location_strategy_javascript/webratlinkwithin.js", "lib/webrat/selenium/location_strategy_javascript/webratselectwithoption.js", "lib/webrat/selenium/matchers.rb", "lib/webrat/selenium/selenium_extensions.js", "lib/webrat/selenium/selenium_session.rb", "lib/webrat/selenium.rb", "lib/webrat/sinatra.rb", "lib/webrat.rb", "vendor/selenium-server.jar"] + s.files = ["History.txt", "install.rb", "MIT-LICENSE.txt", "README.rdoc", "Rakefile", "lib/webrat", "lib/webrat/core", "lib/webrat/core/configuration.rb", "lib/webrat/core/elements", "lib/webrat/core/elements/area.rb", "lib/webrat/core/elements/element.rb", "lib/webrat/core/elements/field.rb", "lib/webrat/core/elements/form.rb", "lib/webrat/core/elements/label.rb", "lib/webrat/core/elements/link.rb", "lib/webrat/core/elements/select_option.rb", "lib/webrat/core/locators", "lib/webrat/core/locators/area_locator.rb", "lib/webrat/core/locators/button_locator.rb", "lib/webrat/core/locators/field_by_id_locator.rb", "lib/webrat/core/locators/field_labeled_locator.rb", "lib/webrat/core/locators/field_locator.rb", "lib/webrat/core/locators/field_named_locator.rb", "lib/webrat/core/locators/form_locator.rb", "lib/webrat/core/locators/label_locator.rb", "lib/webrat/core/locators/link_locator.rb", "lib/webrat/core/locators/locator.rb", "lib/webrat/core/locators/select_option_locator.rb", "lib/webrat/core/locators.rb", "lib/webrat/core/logging.rb", "lib/webrat/core/matchers", "lib/webrat/core/matchers/have_content.rb", "lib/webrat/core/matchers/have_selector.rb", "lib/webrat/core/matchers/have_tag.rb", "lib/webrat/core/matchers/have_xpath.rb", "lib/webrat/core/matchers.rb", "lib/webrat/core/methods.rb", "lib/webrat/core/mime.rb", "lib/webrat/core/save_and_open_page.rb", "lib/webrat/core/scope.rb", "lib/webrat/core/session.rb", "lib/webrat/core/xml", "lib/webrat/core/xml/hpricot.rb", "lib/webrat/core/xml/nokogiri.rb", "lib/webrat/core/xml/rexml.rb", "lib/webrat/core/xml.rb", "lib/webrat/core.rb", "lib/webrat/core_extensions", "lib/webrat/core_extensions/blank.rb", "lib/webrat/core_extensions/deprecate.rb", "lib/webrat/core_extensions/detect_mapped.rb", "lib/webrat/core_extensions/hash_with_indifferent_access.rb", "lib/webrat/core_extensions/meta_class.rb", "lib/webrat/core_extensions/nil_to_param.rb", "lib/webrat/mechanize.rb", "lib/webrat/merb.rb", "lib/webrat/rack.rb", "lib/webrat/rails.rb", "lib/webrat/rspec-rails.rb", "lib/webrat/selenium", "lib/webrat/selenium/location_strategy_javascript", "lib/webrat/selenium/location_strategy_javascript/button.js", "lib/webrat/selenium/location_strategy_javascript/label.js", "lib/webrat/selenium/location_strategy_javascript/webrat.js", "lib/webrat/selenium/location_strategy_javascript/webratlink.js", "lib/webrat/selenium/location_strategy_javascript/webratlinkwithin.js", "lib/webrat/selenium/location_strategy_javascript/webratselectwithoption.js", "lib/webrat/selenium/matchers.rb", "lib/webrat/selenium/selenium_extensions.js", "lib/webrat/selenium/selenium_session.rb", "lib/webrat/selenium.rb", "lib/webrat/sinatra.rb", "lib/webrat.rb", "vendor/selenium-server.jar"] s.has_rdoc = true s.homepage = %q{http://github.com/brynary/webrat} s.require_paths = ["lib"] @@ -21,11 +21,11 @@ Gem::Specification.new do |s| s.specification_version = 2 if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then - s.add_runtime_dependency(%q, [">= 1.0.6"]) + s.add_runtime_dependency(%q, [">= 1.1.0"]) else - s.add_dependency(%q, [">= 1.0.6"]) + s.add_dependency(%q, [">= 1.1.0"]) end else - s.add_dependency(%q, [">= 1.0.6"]) + s.add_dependency(%q, [">= 1.1.0"]) end end From b4dd15025018421956da7f1f94a284baec950e9a Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Mon, 29 Dec 2008 00:18:50 -0500 Subject: [PATCH 2/5] Moving spec/webrat to spec/private and spec/api to spec/public (a la Merb) --- Rakefile | 14 +++++++++----- .../{webrat => private}/core/configuration_spec.rb | 0 spec/{webrat => private}/core/field_spec.rb | 0 spec/{webrat => private}/core/link_spec.rb | 0 spec/{webrat => private}/core/logging_spec.rb | 0 spec/{webrat => private}/core/session_spec.rb | 0 .../mechanize/mechanize_session_spec.rb | 0 .../merb/indifferent_access_spec.rb | 0 spec/{webrat => private}/merb/merb_session_spec.rb | 0 spec/{webrat => private}/nokogiri_spec.rb | 0 .../rails/attaches_file_spec.rb | 0 .../rails/rails_session_spec.rb | 0 spec/{webrat => private}/sinatra/helper.rb | 0 spec/{webrat => private}/sinatra/sinatra_spec.rb | 0 spec/{api => public}/basic_auth_spec.rb | 0 spec/{api => public}/check_spec.rb | 0 spec/{api => public}/choose_spec.rb | 0 spec/{api => public}/click_area_spec.rb | 0 spec/{api => public}/click_button_spec.rb | 0 spec/{api => public}/click_link_spec.rb | 0 spec/{api => public}/fill_in_spec.rb | 0 .../locators/field_by_xpath_spec.rb | 0 .../{api => public}/locators/field_labeled_spec.rb | 0 .../{api => public}/locators/field_with_id_spec.rb | 0 spec/{api => public}/matchers_spec.rb | 0 spec/{api => public}/reload_spec.rb | 0 spec/{api => public}/save_and_open_spec.rb | 0 spec/{api => public}/select_date_spec.rb | 0 spec/{api => public}/select_datetime_spec.rb | 0 spec/{api => public}/select_spec.rb | 0 spec/{api => public}/select_time_spec.rb | 0 spec/{api => public}/set_hidden_field_spec.rb | 0 spec/{api => public}/submit_form_spec.rb | 0 spec/{api => public}/visit_spec.rb | 0 spec/{api => public}/within_spec.rb | 0 35 files changed, 9 insertions(+), 5 deletions(-) rename spec/{webrat => private}/core/configuration_spec.rb (100%) rename spec/{webrat => private}/core/field_spec.rb (100%) rename spec/{webrat => private}/core/link_spec.rb (100%) rename spec/{webrat => private}/core/logging_spec.rb (100%) rename spec/{webrat => private}/core/session_spec.rb (100%) rename spec/{webrat => private}/mechanize/mechanize_session_spec.rb (100%) rename spec/{webrat => private}/merb/indifferent_access_spec.rb (100%) rename spec/{webrat => private}/merb/merb_session_spec.rb (100%) rename spec/{webrat => private}/nokogiri_spec.rb (100%) rename spec/{webrat => private}/rails/attaches_file_spec.rb (100%) rename spec/{webrat => private}/rails/rails_session_spec.rb (100%) rename spec/{webrat => private}/sinatra/helper.rb (100%) rename spec/{webrat => private}/sinatra/sinatra_spec.rb (100%) rename spec/{api => public}/basic_auth_spec.rb (100%) rename spec/{api => public}/check_spec.rb (100%) rename spec/{api => public}/choose_spec.rb (100%) rename spec/{api => public}/click_area_spec.rb (100%) rename spec/{api => public}/click_button_spec.rb (100%) rename spec/{api => public}/click_link_spec.rb (100%) rename spec/{api => public}/fill_in_spec.rb (100%) rename spec/{api => public}/locators/field_by_xpath_spec.rb (100%) rename spec/{api => public}/locators/field_labeled_spec.rb (100%) rename spec/{api => public}/locators/field_with_id_spec.rb (100%) rename spec/{api => public}/matchers_spec.rb (100%) rename spec/{api => public}/reload_spec.rb (100%) rename spec/{api => public}/save_and_open_spec.rb (100%) rename spec/{api => public}/select_date_spec.rb (100%) rename spec/{api => public}/select_datetime_spec.rb (100%) rename spec/{api => public}/select_spec.rb (100%) rename spec/{api => public}/select_time_spec.rb (100%) rename spec/{api => public}/set_hidden_field_spec.rb (100%) rename spec/{api => public}/submit_form_spec.rb (100%) rename spec/{api => public}/visit_spec.rb (100%) rename spec/{api => public}/within_spec.rb (100%) diff --git a/Rakefile b/Rakefile index 44bd364..867aee7 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,4 @@ -require 'rubygems' +# require 'rubygems' require "rake/gempackagetask" require 'rake/rdoctask' require "rake/clean" @@ -52,13 +52,13 @@ end desc "Run API and Core specs" Spec::Rake::SpecTask.new do |t| t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""] - t.spec_files = FileList['spec/**/*_spec.rb'] + t.spec_files = FileList['spec/public/*_spec.rb'] + FileList['spec/private/*_spec.rb'] end desc "Run all specs in spec directory with RCov" Spec::Rake::SpecTask.new(:rcov) do |t| t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""] - t.spec_files = FileList['spec/**/*_spec.rb'] + t.spec_files = FileList['spec/public/*_spec.rb'] + FileList['spec/private/*_spec.rb'] t.rcov = true t.rcov_opts = lambda do IO.readlines(File.dirname(__FILE__) + "/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten @@ -71,8 +71,8 @@ end desc 'Install the package as a gem.' task :install_gem => [:clean, :package] do - gem = Dir['pkg/*.gem'].first - sh "sudo gem install --local #{gem}" + gem_filename = Dir['pkg/*.gem'].first + sh "sudo gem install --local #{gem_filename}" end desc "Delete generated RDoc" @@ -99,6 +99,10 @@ task :spec_deps do end end +task :prepare do + system "ln -s ../../../../.. ./spec/integration/rails/vendor/plugins/webrat" +end + task :default => :spec task :precommit => ["spec", "spec:jruby"] \ No newline at end of file diff --git a/spec/webrat/core/configuration_spec.rb b/spec/private/core/configuration_spec.rb similarity index 100% rename from spec/webrat/core/configuration_spec.rb rename to spec/private/core/configuration_spec.rb diff --git a/spec/webrat/core/field_spec.rb b/spec/private/core/field_spec.rb similarity index 100% rename from spec/webrat/core/field_spec.rb rename to spec/private/core/field_spec.rb diff --git a/spec/webrat/core/link_spec.rb b/spec/private/core/link_spec.rb similarity index 100% rename from spec/webrat/core/link_spec.rb rename to spec/private/core/link_spec.rb diff --git a/spec/webrat/core/logging_spec.rb b/spec/private/core/logging_spec.rb similarity index 100% rename from spec/webrat/core/logging_spec.rb rename to spec/private/core/logging_spec.rb diff --git a/spec/webrat/core/session_spec.rb b/spec/private/core/session_spec.rb similarity index 100% rename from spec/webrat/core/session_spec.rb rename to spec/private/core/session_spec.rb diff --git a/spec/webrat/mechanize/mechanize_session_spec.rb b/spec/private/mechanize/mechanize_session_spec.rb similarity index 100% rename from spec/webrat/mechanize/mechanize_session_spec.rb rename to spec/private/mechanize/mechanize_session_spec.rb diff --git a/spec/webrat/merb/indifferent_access_spec.rb b/spec/private/merb/indifferent_access_spec.rb similarity index 100% rename from spec/webrat/merb/indifferent_access_spec.rb rename to spec/private/merb/indifferent_access_spec.rb diff --git a/spec/webrat/merb/merb_session_spec.rb b/spec/private/merb/merb_session_spec.rb similarity index 100% rename from spec/webrat/merb/merb_session_spec.rb rename to spec/private/merb/merb_session_spec.rb diff --git a/spec/webrat/nokogiri_spec.rb b/spec/private/nokogiri_spec.rb similarity index 100% rename from spec/webrat/nokogiri_spec.rb rename to spec/private/nokogiri_spec.rb diff --git a/spec/webrat/rails/attaches_file_spec.rb b/spec/private/rails/attaches_file_spec.rb similarity index 100% rename from spec/webrat/rails/attaches_file_spec.rb rename to spec/private/rails/attaches_file_spec.rb diff --git a/spec/webrat/rails/rails_session_spec.rb b/spec/private/rails/rails_session_spec.rb similarity index 100% rename from spec/webrat/rails/rails_session_spec.rb rename to spec/private/rails/rails_session_spec.rb diff --git a/spec/webrat/sinatra/helper.rb b/spec/private/sinatra/helper.rb similarity index 100% rename from spec/webrat/sinatra/helper.rb rename to spec/private/sinatra/helper.rb diff --git a/spec/webrat/sinatra/sinatra_spec.rb b/spec/private/sinatra/sinatra_spec.rb similarity index 100% rename from spec/webrat/sinatra/sinatra_spec.rb rename to spec/private/sinatra/sinatra_spec.rb diff --git a/spec/api/basic_auth_spec.rb b/spec/public/basic_auth_spec.rb similarity index 100% rename from spec/api/basic_auth_spec.rb rename to spec/public/basic_auth_spec.rb diff --git a/spec/api/check_spec.rb b/spec/public/check_spec.rb similarity index 100% rename from spec/api/check_spec.rb rename to spec/public/check_spec.rb diff --git a/spec/api/choose_spec.rb b/spec/public/choose_spec.rb similarity index 100% rename from spec/api/choose_spec.rb rename to spec/public/choose_spec.rb diff --git a/spec/api/click_area_spec.rb b/spec/public/click_area_spec.rb similarity index 100% rename from spec/api/click_area_spec.rb rename to spec/public/click_area_spec.rb diff --git a/spec/api/click_button_spec.rb b/spec/public/click_button_spec.rb similarity index 100% rename from spec/api/click_button_spec.rb rename to spec/public/click_button_spec.rb diff --git a/spec/api/click_link_spec.rb b/spec/public/click_link_spec.rb similarity index 100% rename from spec/api/click_link_spec.rb rename to spec/public/click_link_spec.rb diff --git a/spec/api/fill_in_spec.rb b/spec/public/fill_in_spec.rb similarity index 100% rename from spec/api/fill_in_spec.rb rename to spec/public/fill_in_spec.rb diff --git a/spec/api/locators/field_by_xpath_spec.rb b/spec/public/locators/field_by_xpath_spec.rb similarity index 100% rename from spec/api/locators/field_by_xpath_spec.rb rename to spec/public/locators/field_by_xpath_spec.rb diff --git a/spec/api/locators/field_labeled_spec.rb b/spec/public/locators/field_labeled_spec.rb similarity index 100% rename from spec/api/locators/field_labeled_spec.rb rename to spec/public/locators/field_labeled_spec.rb diff --git a/spec/api/locators/field_with_id_spec.rb b/spec/public/locators/field_with_id_spec.rb similarity index 100% rename from spec/api/locators/field_with_id_spec.rb rename to spec/public/locators/field_with_id_spec.rb diff --git a/spec/api/matchers_spec.rb b/spec/public/matchers_spec.rb similarity index 100% rename from spec/api/matchers_spec.rb rename to spec/public/matchers_spec.rb diff --git a/spec/api/reload_spec.rb b/spec/public/reload_spec.rb similarity index 100% rename from spec/api/reload_spec.rb rename to spec/public/reload_spec.rb diff --git a/spec/api/save_and_open_spec.rb b/spec/public/save_and_open_spec.rb similarity index 100% rename from spec/api/save_and_open_spec.rb rename to spec/public/save_and_open_spec.rb diff --git a/spec/api/select_date_spec.rb b/spec/public/select_date_spec.rb similarity index 100% rename from spec/api/select_date_spec.rb rename to spec/public/select_date_spec.rb diff --git a/spec/api/select_datetime_spec.rb b/spec/public/select_datetime_spec.rb similarity index 100% rename from spec/api/select_datetime_spec.rb rename to spec/public/select_datetime_spec.rb diff --git a/spec/api/select_spec.rb b/spec/public/select_spec.rb similarity index 100% rename from spec/api/select_spec.rb rename to spec/public/select_spec.rb diff --git a/spec/api/select_time_spec.rb b/spec/public/select_time_spec.rb similarity index 100% rename from spec/api/select_time_spec.rb rename to spec/public/select_time_spec.rb diff --git a/spec/api/set_hidden_field_spec.rb b/spec/public/set_hidden_field_spec.rb similarity index 100% rename from spec/api/set_hidden_field_spec.rb rename to spec/public/set_hidden_field_spec.rb diff --git a/spec/api/submit_form_spec.rb b/spec/public/submit_form_spec.rb similarity index 100% rename from spec/api/submit_form_spec.rb rename to spec/public/submit_form_spec.rb diff --git a/spec/api/visit_spec.rb b/spec/public/visit_spec.rb similarity index 100% rename from spec/api/visit_spec.rb rename to spec/public/visit_spec.rb diff --git a/spec/api/within_spec.rb b/spec/public/within_spec.rb similarity index 100% rename from spec/api/within_spec.rb rename to spec/public/within_spec.rb From 39e0200608ea9fc6b6e5f015b2b1592da8154c85 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Mon, 29 Dec 2008 01:11:41 -0500 Subject: [PATCH 3/5] Adding a Rails app for integration testing --- Rakefile | 12 +- spec/integration/rails/.gitignore | 1 + spec/integration/rails/Rakefile | 10 ++ .../rails/app/controllers/application.rb | 15 +++ spec/integration/rails/config/boot.rb | 109 ++++++++++++++++++ spec/integration/rails/config/environment.rb | 75 ++++++++++++ .../rails/config/environments/development.rb | 17 +++ .../rails/config/environments/test.rb | 22 ++++ .../rails/config/initializers/inflections.rb | 10 ++ .../rails/config/initializers/mime_types.rb | 5 + .../config/initializers/new_rails_defaults.rb | 17 +++ spec/integration/rails/config/locales/en.yml | 5 + spec/integration/rails/config/routes.rb | 43 +++++++ spec/integration/rails/public/404.html | 30 +++++ spec/integration/rails/public/422.html | 30 +++++ spec/integration/rails/public/500.html | 33 ++++++ spec/integration/rails/script/about | 4 + spec/integration/rails/script/console | 3 + spec/integration/rails/script/dbconsole | 3 + spec/integration/rails/script/destroy | 3 + spec/integration/rails/script/generate | 3 + .../rails/script/performance/benchmarker | 3 + .../rails/script/performance/profiler | 3 + .../rails/script/performance/request | 3 + spec/integration/rails/script/plugin | 3 + .../rails/script/process/inspector | 3 + spec/integration/rails/script/process/reaper | 3 + spec/integration/rails/script/process/spawner | 3 + spec/integration/rails/script/runner | 3 + spec/integration/rails/script/server | 3 + .../rails/test/integration/webrat_test.rb | 7 ++ spec/integration/rails/test/test_helper.rb | 38 ++++++ 32 files changed, 521 insertions(+), 1 deletion(-) create mode 100644 spec/integration/rails/.gitignore create mode 100644 spec/integration/rails/Rakefile create mode 100644 spec/integration/rails/app/controllers/application.rb create mode 100644 spec/integration/rails/config/boot.rb create mode 100644 spec/integration/rails/config/environment.rb create mode 100644 spec/integration/rails/config/environments/development.rb create mode 100644 spec/integration/rails/config/environments/test.rb create mode 100644 spec/integration/rails/config/initializers/inflections.rb create mode 100644 spec/integration/rails/config/initializers/mime_types.rb create mode 100644 spec/integration/rails/config/initializers/new_rails_defaults.rb create mode 100644 spec/integration/rails/config/locales/en.yml create mode 100644 spec/integration/rails/config/routes.rb create mode 100644 spec/integration/rails/public/404.html create mode 100644 spec/integration/rails/public/422.html create mode 100644 spec/integration/rails/public/500.html create mode 100755 spec/integration/rails/script/about create mode 100755 spec/integration/rails/script/console create mode 100755 spec/integration/rails/script/dbconsole create mode 100755 spec/integration/rails/script/destroy create mode 100755 spec/integration/rails/script/generate create mode 100755 spec/integration/rails/script/performance/benchmarker create mode 100755 spec/integration/rails/script/performance/profiler create mode 100755 spec/integration/rails/script/performance/request create mode 100755 spec/integration/rails/script/plugin create mode 100755 spec/integration/rails/script/process/inspector create mode 100755 spec/integration/rails/script/process/reaper create mode 100755 spec/integration/rails/script/process/spawner create mode 100755 spec/integration/rails/script/runner create mode 100755 spec/integration/rails/script/server create mode 100644 spec/integration/rails/test/integration/webrat_test.rb create mode 100644 spec/integration/rails/test/test_helper.rb diff --git a/Rakefile b/Rakefile index 867aee7..889e1f8 100644 --- a/Rakefile +++ b/Rakefile @@ -103,6 +103,16 @@ task :prepare do system "ln -s ../../../../.. ./spec/integration/rails/vendor/plugins/webrat" end +namespace :spec do + desc "Run the integration specs" + task :integration do + Dir.chdir "spec/integration/rails" do + result = system "rake test:integration" + raise "Tests failed" unless result + end + end +end + task :default => :spec -task :precommit => ["spec", "spec:jruby"] \ No newline at end of file +task :precommit => ["spec", "spec:jruby", "spec:integration"] \ No newline at end of file diff --git a/spec/integration/rails/.gitignore b/spec/integration/rails/.gitignore new file mode 100644 index 0000000..ea0fb5d --- /dev/null +++ b/spec/integration/rails/.gitignore @@ -0,0 +1 @@ +vendor/plugins/webrat \ No newline at end of file diff --git a/spec/integration/rails/Rakefile b/spec/integration/rails/Rakefile new file mode 100644 index 0000000..3bb0e85 --- /dev/null +++ b/spec/integration/rails/Rakefile @@ -0,0 +1,10 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require(File.join(File.dirname(__FILE__), 'config', 'boot')) + +require 'rake' +require 'rake/testtask' +require 'rake/rdoctask' + +require 'tasks/rails' diff --git a/spec/integration/rails/app/controllers/application.rb b/spec/integration/rails/app/controllers/application.rb new file mode 100644 index 0000000..58b3052 --- /dev/null +++ b/spec/integration/rails/app/controllers/application.rb @@ -0,0 +1,15 @@ +# Filters added to this controller apply to all controllers in the application. +# Likewise, all the methods added will be available for all controllers. + +class ApplicationController < ActionController::Base + helper :all # include all helpers, all the time + + # See ActionController::RequestForgeryProtection for details + # Uncomment the :secret if you're not using the cookie session store + protect_from_forgery # :secret => 'ceaca978d06f1c9db5c84193c1447572' + + # See ActionController::Base for details + # Uncomment this to filter the contents of submitted sensitive data parameters + # from your application log (in this case, all fields with names like "password"). + # filter_parameter_logging :password +end diff --git a/spec/integration/rails/config/boot.rb b/spec/integration/rails/config/boot.rb new file mode 100644 index 0000000..0a51688 --- /dev/null +++ b/spec/integration/rails/config/boot.rb @@ -0,0 +1,109 @@ +# Don't change this file! +# Configure your app in config/environment.rb and config/environments/*.rb + +RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) + +module Rails + class << self + def boot! + unless booted? + preinitialize + pick_boot.run + end + end + + def booted? + defined? Rails::Initializer + end + + def pick_boot + (vendor_rails? ? VendorBoot : GemBoot).new + end + + def vendor_rails? + File.exist?("#{RAILS_ROOT}/vendor/rails") + end + + def preinitialize + load(preinitializer_path) if File.exist?(preinitializer_path) + end + + def preinitializer_path + "#{RAILS_ROOT}/config/preinitializer.rb" + end + end + + class Boot + def run + load_initializer + Rails::Initializer.run(:set_load_path) + end + end + + class VendorBoot < Boot + def load_initializer + require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer" + Rails::Initializer.run(:install_gem_spec_stubs) + end + end + + class GemBoot < Boot + def load_initializer + self.class.load_rubygems + load_rails_gem + require 'initializer' + end + + def load_rails_gem + if version = self.class.gem_version + gem 'rails', version + else + gem 'rails' + end + rescue Gem::LoadError => load_error + $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.) + exit 1 + end + + class << self + def rubygems_version + Gem::RubyGemsVersion rescue nil + end + + def gem_version + if defined? RAILS_GEM_VERSION + RAILS_GEM_VERSION + elsif ENV.include?('RAILS_GEM_VERSION') + ENV['RAILS_GEM_VERSION'] + else + parse_gem_version(read_environment_rb) + end + end + + def load_rubygems + require 'rubygems' + min_version = '1.3.1' + unless rubygems_version >= min_version + $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.) + exit 1 + end + + rescue LoadError + $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org) + exit 1 + end + + def parse_gem_version(text) + $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/ + end + + private + def read_environment_rb + File.read("#{RAILS_ROOT}/config/environment.rb") + end + end + end +end + +# All that for this: +Rails.boot! diff --git a/spec/integration/rails/config/environment.rb b/spec/integration/rails/config/environment.rb new file mode 100644 index 0000000..279f1ab --- /dev/null +++ b/spec/integration/rails/config/environment.rb @@ -0,0 +1,75 @@ +# Be sure to restart your server when you modify this file + +# Uncomment below to force Rails into production mode when +# you don't control web/app server and can't set it the proper way +# ENV['RAILS_ENV'] ||= 'production' + +# Specifies gem version of Rails to use when vendor/rails is not present +RAILS_GEM_VERSION = '2.2.2' unless defined? RAILS_GEM_VERSION + +# Bootstrap the Rails environment, frameworks, and default configuration +require File.join(File.dirname(__FILE__), 'boot') + +Rails::Initializer.run do |config| + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + # See Rails::Configuration for more options. + + # Skip frameworks you're not going to use. To use Rails without a database + # you must remove the Active Record framework. + config.frameworks -= [ :active_record, :active_resource, :action_mailer ] + + # Specify gems that this application depends on. + # They can then be installed with "rake gems:install" on new installations. + # You have to specify the :lib option for libraries, where the Gem name (sqlite3-ruby) differs from the file itself (sqlite3) + # config.gem "bj" + # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net" + # config.gem "sqlite3-ruby", :lib => "sqlite3" + # config.gem "aws-s3", :lib => "aws/s3" + + # Only load the plugins named here, in the order given. By default, all plugins + # in vendor/plugins are loaded in alphabetical order. + # :all can be used as a placeholder for all plugins not explicitly named + # config.plugins = [ :exception_notification, :ssl_requirement, :all ] + + # Add additional load paths for your own custom dirs + # config.load_paths += %W( #{RAILS_ROOT}/extras ) + + # Force all environments to use the same logger level + # (by default production uses :info, the others :debug) + # config.log_level = :debug + + # Make Time.zone default to the specified zone, and make Active Record store time values + # in the database in UTC, and return them converted to the specified local zone. + # Run "rake -D time" for a list of tasks for finding time zone names. Comment line to use default local time. + config.time_zone = 'UTC' + + # The internationalization framework can be changed to have another default locale (standard is :en) or more load paths. + # All files from config/locales/*.rb,yml are added automatically. + # config.i18n.load_path << Dir[File.join(RAILS_ROOT, 'my', 'locales', '*.{rb,yml}')] + # config.i18n.default_locale = :de + + # Your secret key for verifying cookie session data integrity. + # If you change this key, all old sessions will become invalid! + # Make sure the secret is at least 30 characters and all random, + # no regular words or you'll be exposed to dictionary attacks. + config.action_controller.session = { + :session_key => '_rails_app_session', + :secret => '81f33872c27349e86f1dc2cd6708995b9c26578e6e2d8992e567cd64d96e844343149f6e2f44bf178304141db9ce39e741e0e60699867c29c51c6d7ef7dc9556' + } + + # Use the database for sessions instead of the cookie-based default, + # which shouldn't be used to store highly confidential information + # (create the session table with "rake db:sessions:create") + # config.action_controller.session_store = :active_record_store + + # Use SQL instead of Active Record's schema dumper when creating the test database. + # This is necessary if your schema can't be completely dumped by the schema dumper, + # like if you have constraints or database-specific column types + # config.active_record.schema_format = :sql + + # Activate observers that should always be running + # Please note that observers generated using script/generate observer need to have an _observer suffix + # config.active_record.observers = :cacher, :garbage_collector, :forum_observer +end diff --git a/spec/integration/rails/config/environments/development.rb b/spec/integration/rails/config/environments/development.rb new file mode 100644 index 0000000..85c9a60 --- /dev/null +++ b/spec/integration/rails/config/environments/development.rb @@ -0,0 +1,17 @@ +# Settings specified here will take precedence over those in config/environment.rb + +# In the development environment your application's code is reloaded on +# every request. This slows down response time but is perfect for development +# since you don't have to restart the webserver when you make code changes. +config.cache_classes = false + +# Log error messages when you accidentally call methods on nil. +config.whiny_nils = true + +# Show full error reports and disable caching +config.action_controller.consider_all_requests_local = true +config.action_view.debug_rjs = true +config.action_controller.perform_caching = false + +# Don't care if the mailer can't send +config.action_mailer.raise_delivery_errors = false \ No newline at end of file diff --git a/spec/integration/rails/config/environments/test.rb b/spec/integration/rails/config/environments/test.rb new file mode 100644 index 0000000..1e709e1 --- /dev/null +++ b/spec/integration/rails/config/environments/test.rb @@ -0,0 +1,22 @@ +# Settings specified here will take precedence over those in config/environment.rb + +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! +config.cache_classes = true + +# Log error messages when you accidentally call methods on nil. +config.whiny_nils = true + +# Show full error reports and disable caching +config.action_controller.consider_all_requests_local = true +config.action_controller.perform_caching = false + +# Disable request forgery protection in test environment +config.action_controller.allow_forgery_protection = false + +# Tell Action Mailer not to deliver emails to the real world. +# The :test delivery method accumulates sent emails in the +# ActionMailer::Base.deliveries array. +config.action_mailer.delivery_method = :test diff --git a/spec/integration/rails/config/initializers/inflections.rb b/spec/integration/rails/config/initializers/inflections.rb new file mode 100644 index 0000000..d531b8b --- /dev/null +++ b/spec/integration/rails/config/initializers/inflections.rb @@ -0,0 +1,10 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format +# (all these examples are active by default): +# ActiveSupport::Inflector.inflections do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end diff --git a/spec/integration/rails/config/initializers/mime_types.rb b/spec/integration/rails/config/initializers/mime_types.rb new file mode 100644 index 0000000..72aca7e --- /dev/null +++ b/spec/integration/rails/config/initializers/mime_types.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf +# Mime::Type.register_alias "text/html", :iphone diff --git a/spec/integration/rails/config/initializers/new_rails_defaults.rb b/spec/integration/rails/config/initializers/new_rails_defaults.rb new file mode 100644 index 0000000..78e0117 --- /dev/null +++ b/spec/integration/rails/config/initializers/new_rails_defaults.rb @@ -0,0 +1,17 @@ +# These settings change the behavior of Rails 2 apps and will be defaults +# for Rails 3. You can remove this initializer when Rails 3 is released. + +if defined?(ActiveRecord) + # Include Active Record class name as root for JSON serialized output. + ActiveRecord::Base.include_root_in_json = true + + # Store the full class name (including module namespace) in STI type column. + ActiveRecord::Base.store_full_sti_class = true +end + +# Use ISO 8601 format for JSON serialized times and dates. +ActiveSupport.use_standard_json_time_format = true + +# Don't escape HTML entities in JSON, leave that for the #json_escape helper. +# if you're including raw json in an HTML page. +ActiveSupport.escape_html_entities_in_json = false \ No newline at end of file diff --git a/spec/integration/rails/config/locales/en.yml b/spec/integration/rails/config/locales/en.yml new file mode 100644 index 0000000..f265c06 --- /dev/null +++ b/spec/integration/rails/config/locales/en.yml @@ -0,0 +1,5 @@ +# Sample localization file for English. Add more files in this directory for other locales. +# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. + +en: + hello: "Hello world" \ No newline at end of file diff --git a/spec/integration/rails/config/routes.rb b/spec/integration/rails/config/routes.rb new file mode 100644 index 0000000..4f3d9d2 --- /dev/null +++ b/spec/integration/rails/config/routes.rb @@ -0,0 +1,43 @@ +ActionController::Routing::Routes.draw do |map| + # The priority is based upon order of creation: first created -> highest priority. + + # Sample of regular route: + # map.connect 'products/:id', :controller => 'catalog', :action => 'view' + # Keep in mind you can assign values other than :controller and :action + + # Sample of named route: + # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase' + # This route can be invoked with purchase_url(:id => product.id) + + # Sample resource route (maps HTTP verbs to controller actions automatically): + # map.resources :products + + # Sample resource route with options: + # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get } + + # Sample resource route with sub-resources: + # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller + + # Sample resource route with more complex sub-resources + # map.resources :products do |products| + # products.resources :comments + # products.resources :sales, :collection => { :recent => :get } + # end + + # Sample resource route within a namespace: + # map.namespace :admin do |admin| + # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb) + # admin.resources :products + # end + + # You can have the root of your site routed with map.root -- just remember to delete public/index.html. + # map.root :controller => "welcome" + + # See how all your routes lay out with "rake routes" + + # Install the default routes as the lowest priority. + # Note: These default routes make all actions in every controller accessible via GET requests. You should + # consider removing the them or commenting them out if you're using named routes and resources. + map.connect ':controller/:action/:id' + map.connect ':controller/:action/:id.:format' +end diff --git a/spec/integration/rails/public/404.html b/spec/integration/rails/public/404.html new file mode 100644 index 0000000..eff660b --- /dev/null +++ b/spec/integration/rails/public/404.html @@ -0,0 +1,30 @@ + + + + + + + The page you were looking for doesn't exist (404) + + + + + +
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+ + \ No newline at end of file diff --git a/spec/integration/rails/public/422.html b/spec/integration/rails/public/422.html new file mode 100644 index 0000000..b54e4a3 --- /dev/null +++ b/spec/integration/rails/public/422.html @@ -0,0 +1,30 @@ + + + + + + + The change you wanted was rejected (422) + + + + + +
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+ + \ No newline at end of file diff --git a/spec/integration/rails/public/500.html b/spec/integration/rails/public/500.html new file mode 100644 index 0000000..0cd07c1 --- /dev/null +++ b/spec/integration/rails/public/500.html @@ -0,0 +1,33 @@ + + + + + + + We're sorry, but something went wrong (500) + + + + + +
+

We're sorry, but something went wrong.

+

We've been notified about this issue and we'll take a look at it shortly.

+

(If you're the administrator of this website, then please read + the log file "<%=h RAILS_ENV %>.log" + to find out what went wrong.)

+
+ + diff --git a/spec/integration/rails/script/about b/spec/integration/rails/script/about new file mode 100755 index 0000000..ed8deb0 --- /dev/null +++ b/spec/integration/rails/script/about @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +$LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" +require 'commands/about' \ No newline at end of file diff --git a/spec/integration/rails/script/console b/spec/integration/rails/script/console new file mode 100755 index 0000000..498077a --- /dev/null +++ b/spec/integration/rails/script/console @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/console' diff --git a/spec/integration/rails/script/dbconsole b/spec/integration/rails/script/dbconsole new file mode 100755 index 0000000..caa60ce --- /dev/null +++ b/spec/integration/rails/script/dbconsole @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/dbconsole' diff --git a/spec/integration/rails/script/destroy b/spec/integration/rails/script/destroy new file mode 100755 index 0000000..a4df765 --- /dev/null +++ b/spec/integration/rails/script/destroy @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/destroy' diff --git a/spec/integration/rails/script/generate b/spec/integration/rails/script/generate new file mode 100755 index 0000000..173a9f1 --- /dev/null +++ b/spec/integration/rails/script/generate @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/generate' diff --git a/spec/integration/rails/script/performance/benchmarker b/spec/integration/rails/script/performance/benchmarker new file mode 100755 index 0000000..c842d35 --- /dev/null +++ b/spec/integration/rails/script/performance/benchmarker @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../../config/boot' +require 'commands/performance/benchmarker' diff --git a/spec/integration/rails/script/performance/profiler b/spec/integration/rails/script/performance/profiler new file mode 100755 index 0000000..d855ac8 --- /dev/null +++ b/spec/integration/rails/script/performance/profiler @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../../config/boot' +require 'commands/performance/profiler' diff --git a/spec/integration/rails/script/performance/request b/spec/integration/rails/script/performance/request new file mode 100755 index 0000000..ae3f38c --- /dev/null +++ b/spec/integration/rails/script/performance/request @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../../config/boot' +require 'commands/performance/request' diff --git a/spec/integration/rails/script/plugin b/spec/integration/rails/script/plugin new file mode 100755 index 0000000..87cd207 --- /dev/null +++ b/spec/integration/rails/script/plugin @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/plugin' diff --git a/spec/integration/rails/script/process/inspector b/spec/integration/rails/script/process/inspector new file mode 100755 index 0000000..bf25ad8 --- /dev/null +++ b/spec/integration/rails/script/process/inspector @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../../config/boot' +require 'commands/process/inspector' diff --git a/spec/integration/rails/script/process/reaper b/spec/integration/rails/script/process/reaper new file mode 100755 index 0000000..c77f045 --- /dev/null +++ b/spec/integration/rails/script/process/reaper @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../../config/boot' +require 'commands/process/reaper' diff --git a/spec/integration/rails/script/process/spawner b/spec/integration/rails/script/process/spawner new file mode 100755 index 0000000..7118f39 --- /dev/null +++ b/spec/integration/rails/script/process/spawner @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../../config/boot' +require 'commands/process/spawner' diff --git a/spec/integration/rails/script/runner b/spec/integration/rails/script/runner new file mode 100755 index 0000000..a4a7cb2 --- /dev/null +++ b/spec/integration/rails/script/runner @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/runner' diff --git a/spec/integration/rails/script/server b/spec/integration/rails/script/server new file mode 100755 index 0000000..3c67f39 --- /dev/null +++ b/spec/integration/rails/script/server @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/server' diff --git a/spec/integration/rails/test/integration/webrat_test.rb b/spec/integration/rails/test/integration/webrat_test.rb new file mode 100644 index 0000000..242491a --- /dev/null +++ b/spec/integration/rails/test/integration/webrat_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class WebratTest < ActionController::IntegrationTest + test "should pass" do + assert true + end +end diff --git a/spec/integration/rails/test/test_helper.rb b/spec/integration/rails/test/test_helper.rb new file mode 100644 index 0000000..9f19269 --- /dev/null +++ b/spec/integration/rails/test/test_helper.rb @@ -0,0 +1,38 @@ +ENV["RAILS_ENV"] = "test" +require File.expand_path(File.dirname(__FILE__) + "/../config/environment") +require 'test_help' + +class Test::Unit::TestCase + # Transactional fixtures accelerate your tests by wrapping each test method + # in a transaction that's rolled back on completion. This ensures that the + # test database remains unchanged so your fixtures don't have to be reloaded + # between every test method. Fewer database queries means faster tests. + # + # Read Mike Clark's excellent walkthrough at + # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting + # + # Every Active Record database supports transactions except MyISAM tables + # in MySQL. Turn off transactional fixtures in this case; however, if you + # don't care one way or the other, switching from MyISAM to InnoDB tables + # is recommended. + # + # The only drawback to using transactional fixtures is when you actually + # need to test transactions. Since your test is bracketed by a transaction, + # any transactions started in your code will be automatically rolled back. + self.use_transactional_fixtures = true + + # Instantiated fixtures are slow, but give you @david where otherwise you + # would need people(:david). If you don't want to migrate your existing + # test cases which use the @david style and don't mind the speed hit (each + # instantiated fixtures translates to a database query per test method), + # then set this back to true. + self.use_instantiated_fixtures = false + + # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. + # + # Note: You'll currently still have to declare fixtures explicitly in integration tests + # -- they do not yet inherit this setting + fixtures :all + + # Add more helper methods to be used by all tests here... +end From add38820e58cba6a7e1ee62155c29480a9d1d913 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Mon, 29 Dec 2008 01:30:26 -0500 Subject: [PATCH 4/5] Adding two tests for Rails integration --- .../app/controllers/webrat_controller.rb | 10 ++++ .../rails/app/views/webrat/form.html.erb | 17 +++++++ spec/integration/rails/config/routes.rb | 45 ++---------------- .../rails/test/integration/webrat_test.rb | 14 +++++- spec/integration/rails/test/test_helper.rb | 47 ++++++------------- 5 files changed, 58 insertions(+), 75 deletions(-) create mode 100644 spec/integration/rails/app/controllers/webrat_controller.rb create mode 100644 spec/integration/rails/app/views/webrat/form.html.erb diff --git a/spec/integration/rails/app/controllers/webrat_controller.rb b/spec/integration/rails/app/controllers/webrat_controller.rb new file mode 100644 index 0000000..5a2db67 --- /dev/null +++ b/spec/integration/rails/app/controllers/webrat_controller.rb @@ -0,0 +1,10 @@ +class WebratController < ApplicationController + + def form + end + + def submit + render :text => "OK" + end + +end \ No newline at end of file diff --git a/spec/integration/rails/app/views/webrat/form.html.erb b/spec/integration/rails/app/views/webrat/form.html.erb new file mode 100644 index 0000000..5c89281 --- /dev/null +++ b/spec/integration/rails/app/views/webrat/form.html.erb @@ -0,0 +1,17 @@ +

Webrat Form

+ +<% form_tag submit_path do %> + + + + + + + <%= submit_tag "Test" %> +<% end %> \ No newline at end of file diff --git a/spec/integration/rails/config/routes.rb b/spec/integration/rails/config/routes.rb index 4f3d9d2..7b63461 100644 --- a/spec/integration/rails/config/routes.rb +++ b/spec/integration/rails/config/routes.rb @@ -1,43 +1,6 @@ ActionController::Routing::Routes.draw do |map| - # The priority is based upon order of creation: first created -> highest priority. - - # Sample of regular route: - # map.connect 'products/:id', :controller => 'catalog', :action => 'view' - # Keep in mind you can assign values other than :controller and :action - - # Sample of named route: - # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase' - # This route can be invoked with purchase_url(:id => product.id) - - # Sample resource route (maps HTTP verbs to controller actions automatically): - # map.resources :products - - # Sample resource route with options: - # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get } - - # Sample resource route with sub-resources: - # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller - - # Sample resource route with more complex sub-resources - # map.resources :products do |products| - # products.resources :comments - # products.resources :sales, :collection => { :recent => :get } - # end - - # Sample resource route within a namespace: - # map.namespace :admin do |admin| - # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb) - # admin.resources :products - # end - - # You can have the root of your site routed with map.root -- just remember to delete public/index.html. - # map.root :controller => "welcome" - - # See how all your routes lay out with "rake routes" - - # Install the default routes as the lowest priority. - # Note: These default routes make all actions in every controller accessible via GET requests. You should - # consider removing the them or commenting them out if you're using named routes and resources. - map.connect ':controller/:action/:id' - map.connect ':controller/:action/:id.:format' + map.with_options :controller => "webrat" do |webrat| + webrat.submit "/submit", :action => "submit" + webrat.root :action => "form" + end end diff --git a/spec/integration/rails/test/integration/webrat_test.rb b/spec/integration/rails/test/integration/webrat_test.rb index 242491a..4ecbe27 100644 --- a/spec/integration/rails/test/integration/webrat_test.rb +++ b/spec/integration/rails/test/integration/webrat_test.rb @@ -1,7 +1,17 @@ require 'test_helper' class WebratTest < ActionController::IntegrationTest - test "should pass" do - assert true + test "should visit pages" do + visit root_path + assert_tag "Webrat Form" + assert response.body.include?("Webrat Form") + end + + test "should submit forms" do + visit root_path + fill_in "Text field", :with => "Hello" + check "TOS" + select "January" + click_button "Test" end end diff --git a/spec/integration/rails/test/test_helper.rb b/spec/integration/rails/test/test_helper.rb index 9f19269..d3c3287 100644 --- a/spec/integration/rails/test/test_helper.rb +++ b/spec/integration/rails/test/test_helper.rb @@ -1,38 +1,21 @@ ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' +require "redgreen" -class Test::Unit::TestCase - # Transactional fixtures accelerate your tests by wrapping each test method - # in a transaction that's rolled back on completion. This ensures that the - # test database remains unchanged so your fixtures don't have to be reloaded - # between every test method. Fewer database queries means faster tests. - # - # Read Mike Clark's excellent walkthrough at - # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting - # - # Every Active Record database supports transactions except MyISAM tables - # in MySQL. Turn off transactional fixtures in this case; however, if you - # don't care one way or the other, switching from MyISAM to InnoDB tables - # is recommended. - # - # The only drawback to using transactional fixtures is when you actually - # need to test transactions. Since your test is bracketed by a transaction, - # any transactions started in your code will be automatically rolled back. - self.use_transactional_fixtures = true +require "webrat" - # Instantiated fixtures are slow, but give you @david where otherwise you - # would need people(:david). If you don't want to migrate your existing - # test cases which use the @david style and don't mind the speed hit (each - # instantiated fixtures translates to a database query per test method), - # then set this back to true. - self.use_instantiated_fixtures = false - - # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. - # - # Note: You'll currently still have to declare fixtures explicitly in integration tests - # -- they do not yet inherit this setting - fixtures :all - - # Add more helper methods to be used by all tests here... +Webrat.configure do |config| + config.mode = :rails end + +ActionController::Base.class_eval do + def perform_action + perform_action_without_rescue + end +end +Dispatcher.class_eval do + def self.failsafe_response(output, status, exception = nil) + raise exception + end +end \ No newline at end of file From 2562942b6db665ee171bb15b907fdb4ab6ab2bf7 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Mon, 29 Dec 2008 02:10:05 -0500 Subject: [PATCH 5/5] Adding merb app for integration testing --- Rakefile | 5 + spec/integration/merb/.gitignore | 21 +++ spec/integration/merb/Rakefile | 35 ++++ .../merb/app/controllers/application.rb | 2 + .../merb/app/controllers/exceptions.rb | 13 ++ .../merb/app/controllers/testing.rb | 10 ++ .../views/exceptions/not_acceptable.html.erb | 63 ++++++++ .../app/views/exceptions/not_found.html.erb | 47 ++++++ .../app/views/layout/application.html.erb | 12 ++ .../merb/app/views/testing/show_form.html.erb | 22 +++ .../merb/config/environments/development.rb | 15 ++ .../merb/config/environments/rake.rb | 11 ++ .../merb/config/environments/test.rb | 12 ++ spec/integration/merb/config/init.rb | 25 +++ spec/integration/merb/config/rack.rb | 11 ++ spec/integration/merb/config/router.rb | 31 ++++ spec/integration/merb/spec/spec.opts | 1 + spec/integration/merb/spec/spec_helper.rb | 20 +++ spec/integration/merb/spec/webrat_spec.rb | 17 ++ .../merb/tasks/merb.thor/app_script.rb | 31 ++++ .../merb/tasks/merb.thor/common.rb | 64 ++++++++ .../merb/tasks/merb.thor/gem_ext.rb | 124 +++++++++++++++ .../merb/tasks/merb.thor/main.thor | 150 ++++++++++++++++++ spec/integration/merb/tasks/merb.thor/ops.rb | 93 +++++++++++ .../integration/merb/tasks/merb.thor/utils.rb | 40 +++++ 25 files changed, 875 insertions(+) create mode 100644 spec/integration/merb/.gitignore create mode 100644 spec/integration/merb/Rakefile create mode 100644 spec/integration/merb/app/controllers/application.rb create mode 100644 spec/integration/merb/app/controllers/exceptions.rb create mode 100644 spec/integration/merb/app/controllers/testing.rb create mode 100644 spec/integration/merb/app/views/exceptions/not_acceptable.html.erb create mode 100644 spec/integration/merb/app/views/exceptions/not_found.html.erb create mode 100644 spec/integration/merb/app/views/layout/application.html.erb create mode 100644 spec/integration/merb/app/views/testing/show_form.html.erb create mode 100644 spec/integration/merb/config/environments/development.rb create mode 100644 spec/integration/merb/config/environments/rake.rb create mode 100644 spec/integration/merb/config/environments/test.rb create mode 100644 spec/integration/merb/config/init.rb create mode 100644 spec/integration/merb/config/rack.rb create mode 100644 spec/integration/merb/config/router.rb create mode 100644 spec/integration/merb/spec/spec.opts create mode 100644 spec/integration/merb/spec/spec_helper.rb create mode 100644 spec/integration/merb/spec/webrat_spec.rb create mode 100644 spec/integration/merb/tasks/merb.thor/app_script.rb create mode 100644 spec/integration/merb/tasks/merb.thor/common.rb create mode 100644 spec/integration/merb/tasks/merb.thor/gem_ext.rb create mode 100644 spec/integration/merb/tasks/merb.thor/main.thor create mode 100644 spec/integration/merb/tasks/merb.thor/ops.rb create mode 100644 spec/integration/merb/tasks/merb.thor/utils.rb diff --git a/Rakefile b/Rakefile index 889e1f8..e80cd8e 100644 --- a/Rakefile +++ b/Rakefile @@ -110,6 +110,11 @@ namespace :spec do result = system "rake test:integration" raise "Tests failed" unless result end + + Dir.chdir "spec/integration/merb" do + result = system "rake spec" + raise "Tests failed" unless result + end end end diff --git a/spec/integration/merb/.gitignore b/spec/integration/merb/.gitignore new file mode 100644 index 0000000..753409b --- /dev/null +++ b/spec/integration/merb/.gitignore @@ -0,0 +1,21 @@ +.DS_Store +log/* +tmp/* +TAGS +*~ +.#* +schema/schema.rb +schema/*_structure.sql +schema/*.sqlite3 +schema/*.sqlite +schema/*.db +*.sqlite +*.sqlite3 +*.db +src/* +.hgignore +.hg/* +.svn/* +gems/gems/* +gems/specifications/* +merb_profile_results \ No newline at end of file diff --git a/spec/integration/merb/Rakefile b/spec/integration/merb/Rakefile new file mode 100644 index 0000000..a760c99 --- /dev/null +++ b/spec/integration/merb/Rakefile @@ -0,0 +1,35 @@ +require 'rubygems' +require 'rake/rdoctask' + +require 'merb-core' +require 'merb-core/tasks/merb' + +include FileUtils + +# Load the basic runtime dependencies; this will include +# any plugins and therefore plugin rake tasks. +init_env = ENV['MERB_ENV'] || 'rake' +Merb.load_dependencies(:environment => init_env) + +# Get Merb plugins and dependencies +Merb::Plugins.rakefiles.each { |r| require r } + +# Load any app level custom rakefile extensions from lib/tasks +tasks_path = File.join(File.dirname(__FILE__), "lib", "tasks") +rake_files = Dir["#{tasks_path}/*.rake"] +rake_files.each{|rake_file| load rake_file } + +desc "Start runner environment" +task :merb_env do + Merb.start_environment(:environment => init_env, :adapter => 'runner') +end + +require 'spec/rake/spectask' +require 'merb-core/test/tasks/spectasks' +desc 'Default: run spec examples' +task :default => 'spec' + +############################################################################## +# ADD YOUR CUSTOM TASKS IN /lib/tasks +# NAME YOUR RAKE FILES file_name.rake +############################################################################## diff --git a/spec/integration/merb/app/controllers/application.rb b/spec/integration/merb/app/controllers/application.rb new file mode 100644 index 0000000..5ce39a0 --- /dev/null +++ b/spec/integration/merb/app/controllers/application.rb @@ -0,0 +1,2 @@ +class Application < Merb::Controller +end \ No newline at end of file diff --git a/spec/integration/merb/app/controllers/exceptions.rb b/spec/integration/merb/app/controllers/exceptions.rb new file mode 100644 index 0000000..4fdb566 --- /dev/null +++ b/spec/integration/merb/app/controllers/exceptions.rb @@ -0,0 +1,13 @@ +class Exceptions < Merb::Controller + + # handle NotFound exceptions (404) + def not_found + render :format => :html + end + + # handle NotAcceptable exceptions (406) + def not_acceptable + render :format => :html + end + +end \ No newline at end of file diff --git a/spec/integration/merb/app/controllers/testing.rb b/spec/integration/merb/app/controllers/testing.rb new file mode 100644 index 0000000..40a56da --- /dev/null +++ b/spec/integration/merb/app/controllers/testing.rb @@ -0,0 +1,10 @@ +class Testing < Application + + def show_form + render + end + + def submit_form + end + +end \ No newline at end of file diff --git a/spec/integration/merb/app/views/exceptions/not_acceptable.html.erb b/spec/integration/merb/app/views/exceptions/not_acceptable.html.erb new file mode 100644 index 0000000..a7b7752 --- /dev/null +++ b/spec/integration/merb/app/views/exceptions/not_acceptable.html.erb @@ -0,0 +1,63 @@ +
+
+ + +

pocket rocket web framework

+
+
+ +
+

Exception:

+

<%= request.exceptions.first.message %>

+
+ +
+

Why am I seeing this page?

+

Merb couldn't find an appropriate content_type to return, + based on what you said was available via provides() and + what the client requested.

+ +

How to add a mime-type

+

+      Merb.add_mime_type :pdf, :to_pdf, %w[application/pdf], "Content-Encoding" => "gzip"
+    
+

What this means is:

+
    +
  • Add a mime-type for :pdf
  • +
  • Register the method for converting objects to PDF as #to_pdf.
  • +
  • Register the incoming mime-type "Accept" header as application/pdf.
  • +
  • Specify a new header for PDF types so it will set Content-Encoding to gzip.
  • +
+ +

You can then do:

+

+      class Foo < Application
+        provides :pdf
+      end
+    
+ +

Where can I find help?

+

If you have any questions or if you can't figure something out, please take a + look at our project page, + feel free to come chat at irc.freenode.net, channel #merb, + or post to merb mailing list + on Google Groups.

+ +

What if I've found a bug?

+

If you want to file a bug or make your own contribution to Merb, + feel free to register and create a ticket at our + project development page + on Lighthouse.

+ +

How do I edit this page?

+

You can change what people see when this happens by editing app/views/exceptions/not_acceptable.html.erb.

+ +
+ + +
diff --git a/spec/integration/merb/app/views/exceptions/not_found.html.erb b/spec/integration/merb/app/views/exceptions/not_found.html.erb new file mode 100644 index 0000000..42b41a8 --- /dev/null +++ b/spec/integration/merb/app/views/exceptions/not_found.html.erb @@ -0,0 +1,47 @@ +
+
+ + +

pocket rocket web framework

+
+
+ +
+

Exception:

+

<%= request.exceptions.first.message %>

+
+ +
+

Welcome to Merb!

+

Merb is a light-weight MVC framework written in Ruby. We hope you enjoy it.

+ +

Where can I find help?

+

If you have any questions or if you can't figure something out, please take a + look at our project page, + feel free to come chat at irc.freenode.net, channel #merb, + or post to merb mailing list + on Google Groups.

+ +

What if I've found a bug?

+

If you want to file a bug or make your own contribution to Merb, + feel free to register and create a ticket at our + project development page + on Lighthouse.

+ +

How do I edit this page?

+

You're seeing this page because you need to edit the following files: +

    +
  • config/router.rb (recommended)
  • +
  • app/views/exceptions/not_found.html.erb (recommended)
  • +
  • app/views/layout/application.html.erb (change this layout)
  • +
+

+
+ + +
diff --git a/spec/integration/merb/app/views/layout/application.html.erb b/spec/integration/merb/app/views/layout/application.html.erb new file mode 100644 index 0000000..4637ef2 --- /dev/null +++ b/spec/integration/merb/app/views/layout/application.html.erb @@ -0,0 +1,12 @@ + + + + Fresh Merb App + + + + + <%#= message[:notice] %> + <%= catch_content :for_layout %> + + \ No newline at end of file diff --git a/spec/integration/merb/app/views/testing/show_form.html.erb b/spec/integration/merb/app/views/testing/show_form.html.erb new file mode 100644 index 0000000..cee070b --- /dev/null +++ b/spec/integration/merb/app/views/testing/show_form.html.erb @@ -0,0 +1,22 @@ +

Webrat Form

+ +
+ + + + + + + +
\ No newline at end of file diff --git a/spec/integration/merb/config/environments/development.rb b/spec/integration/merb/config/environments/development.rb new file mode 100644 index 0000000..d6d4ab3 --- /dev/null +++ b/spec/integration/merb/config/environments/development.rb @@ -0,0 +1,15 @@ +Merb.logger.info("Loaded DEVELOPMENT Environment...") +Merb::Config.use { |c| + c[:exception_details] = true + c[:reload_templates] = true + c[:reload_classes] = true + c[:reload_time] = 0.5 + c[:ignore_tampered_cookies] = true + c[:log_auto_flush ] = true + c[:log_level] = :debug + + c[:log_stream] = STDOUT + c[:log_file] = nil + # Or redirect logging into a file: + # c[:log_file] = Merb.root / "log" / "development.log" +} diff --git a/spec/integration/merb/config/environments/rake.rb b/spec/integration/merb/config/environments/rake.rb new file mode 100644 index 0000000..5e4b9a7 --- /dev/null +++ b/spec/integration/merb/config/environments/rake.rb @@ -0,0 +1,11 @@ +Merb.logger.info("Loaded RAKE Environment...") +Merb::Config.use { |c| + c[:exception_details] = true + c[:reload_classes] = false + c[:log_auto_flush ] = true + + c[:log_stream] = STDOUT + c[:log_file] = nil + # Or redirect logging into a file: + # c[:log_file] = Merb.root / "log" / "development.log" +} diff --git a/spec/integration/merb/config/environments/test.rb b/spec/integration/merb/config/environments/test.rb new file mode 100644 index 0000000..671ec76 --- /dev/null +++ b/spec/integration/merb/config/environments/test.rb @@ -0,0 +1,12 @@ +Merb.logger.info("Loaded TEST Environment...") +Merb::Config.use { |c| + c[:testing] = true + c[:exception_details] = true + c[:log_auto_flush ] = true + # log less in testing environment + c[:log_level] = :error + + #c[:log_file] = Merb.root / "log" / "test.log" + # or redirect logger using IO handle + c[:log_stream] = STDOUT +} diff --git a/spec/integration/merb/config/init.rb b/spec/integration/merb/config/init.rb new file mode 100644 index 0000000..e7268e9 --- /dev/null +++ b/spec/integration/merb/config/init.rb @@ -0,0 +1,25 @@ +# Go to http://wiki.merbivore.com/pages/init-rb + +# Specify a specific version of a dependency +# dependency "RedCloth", "> 3.0" + +# use_orm :none +use_test :rspec +use_template_engine :erb + +Merb::Config.use do |c| + c[:use_mutex] = false + c[:session_store] = 'cookie' # can also be 'memory', 'memcache', 'container', 'datamapper + + # cookie session store configuration + c[:session_secret_key] = 'adb9ea7a0e94b5513503f58623a393c5efe18851' # required for cookie session store + c[:session_id_key] = '_merb_session_id' # cookie session id key, defaults to "_session_id" +end + +Merb::BootLoader.before_app_loads do + # This will get executed after dependencies have been loaded but before your app's classes have loaded. +end + +Merb::BootLoader.after_app_loads do + # This will get executed after your app's classes have been loaded. +end \ No newline at end of file diff --git a/spec/integration/merb/config/rack.rb b/spec/integration/merb/config/rack.rb new file mode 100644 index 0000000..494c687 --- /dev/null +++ b/spec/integration/merb/config/rack.rb @@ -0,0 +1,11 @@ +# use PathPrefix Middleware if :path_prefix is set in Merb::Config +if prefix = ::Merb::Config[:path_prefix] + use Merb::Rack::PathPrefix, prefix +end + +# comment this out if you are running merb behind a load balancer +# that serves static files +use Merb::Rack::Static, Merb.dir_for(:public) + +# this is our main merb application +run Merb::Rack::Application.new \ No newline at end of file diff --git a/spec/integration/merb/config/router.rb b/spec/integration/merb/config/router.rb new file mode 100644 index 0000000..6df8fb2 --- /dev/null +++ b/spec/integration/merb/config/router.rb @@ -0,0 +1,31 @@ +# Merb::Router is the request routing mapper for the merb framework. +# +# You can route a specific URL to a controller / action pair: +# +# match("/contact"). +# to(:controller => "info", :action => "contact") +# +# You can define placeholder parts of the url with the :symbol notation. These +# placeholders will be available in the params hash of your controllers. For example: +# +# match("/books/:book_id/:action"). +# to(:controller => "books") +# +# Or, use placeholders in the "to" results for more complicated routing, e.g.: +# +# match("/admin/:module/:controller/:action/:id"). +# to(:controller => ":module/:controller") +# +# You can specify conditions on the placeholder by passing a hash as the second +# argument of "match" +# +# match("/registration/:course_name", :course_name => /^[a-z]{3,5}-\d{5}$/). +# to(:controller => "registration") +# +# You can also use regular expressions, deferred routes, and many other options. +# See merb/specs/merb/router.rb for a fairly complete usage sample. + +Merb.logger.info("Compiling routes...") +Merb::Router.prepare do + match("/").to(:controller => "testing", :action => "show_form") +end \ No newline at end of file diff --git a/spec/integration/merb/spec/spec.opts b/spec/integration/merb/spec/spec.opts new file mode 100644 index 0000000..4e1e0d2 --- /dev/null +++ b/spec/integration/merb/spec/spec.opts @@ -0,0 +1 @@ +--color diff --git a/spec/integration/merb/spec/spec_helper.rb b/spec/integration/merb/spec/spec_helper.rb new file mode 100644 index 0000000..ae04668 --- /dev/null +++ b/spec/integration/merb/spec/spec_helper.rb @@ -0,0 +1,20 @@ +require "rubygems" + +# Add the local gems dir if found within the app root; any dependencies loaded +# hereafter will try to load from the local gems before loading system gems. +if (local_gem_dir = File.join(File.dirname(__FILE__), '..', 'gems')) && $BUNDLE.nil? + $BUNDLE = true; Gem.clear_paths; Gem.path.unshift(local_gem_dir) +end + +require "merb-core" +require "spec" # Satisfies Autotest and anyone else not using the Rake tasks + +# this loads all plugins required in your init file so don't add them +# here again, Merb will do it for you +Merb.start_environment(:testing => true, :adapter => 'runner', :environment => ENV['MERB_ENV'] || 'test') + +Spec::Runner.configure do |config| + config.include(Merb::Test::ViewHelper) + config.include(Merb::Test::RouteHelper) + config.include(Merb::Test::ControllerHelper) +end \ No newline at end of file diff --git a/spec/integration/merb/spec/webrat_spec.rb b/spec/integration/merb/spec/webrat_spec.rb new file mode 100644 index 0000000..cc9fc1b --- /dev/null +++ b/spec/integration/merb/spec/webrat_spec.rb @@ -0,0 +1,17 @@ +require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) + +describe "Webrat" do + it "should visit pages" do + response = visit "/" + response.should contain("Webrat Form") + end + + it "should submit forms" do + visit "/" + fill_in "Text field", :with => "Hello" + check "TOS" + select "January" + click_button "Test" + end + +end \ No newline at end of file diff --git a/spec/integration/merb/tasks/merb.thor/app_script.rb b/spec/integration/merb/tasks/merb.thor/app_script.rb new file mode 100644 index 0000000..fb0e116 --- /dev/null +++ b/spec/integration/merb/tasks/merb.thor/app_script.rb @@ -0,0 +1,31 @@ +#!/usr/bin/env ruby + +# This was added by Merb's bundler + +require "rubygems" +require File.join(File.dirname(__FILE__), "common") + +gems_dir = File.join(File.dirname(__FILE__), '..', 'gems') + +if File.directory?(gems_dir) + $BUNDLE = true + Gem.clear_paths + Gem.path.replace([File.expand_path(gems_dir)]) + ENV["PATH"] = "#{File.dirname(__FILE__)}:#{ENV["PATH"]}" + + gem_file = File.join(gems_dir, "specifications", "<%= spec.name %>-*.gemspec") + + if local_gem = Dir[gem_file].last + version = File.basename(local_gem)[/-([\.\d]+)\.gemspec$/, 1] + end +end + +version ||= "<%= Gem::Requirement.default %>" + +if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then + version = $1 + ARGV.shift +end + +gem '<%= @spec.name %>', version +load '<%= bin_file_name %>' \ No newline at end of file diff --git a/spec/integration/merb/tasks/merb.thor/common.rb b/spec/integration/merb/tasks/merb.thor/common.rb new file mode 100644 index 0000000..0258520 --- /dev/null +++ b/spec/integration/merb/tasks/merb.thor/common.rb @@ -0,0 +1,64 @@ +# This was added via Merb's bundler + +require "rubygems" +require "rubygems/source_index" + +module Gem + BUNDLED_SPECS = File.join(Dir.pwd, "gems", "specifications") + MAIN_INDEX = Gem::SourceIndex.from_gems_in(BUNDLED_SPECS) + FALLBACK_INDEX = Gem::SourceIndex.from_installed_gems + + def self.source_index + MultiSourceIndex.new + end + + def self.searcher + MultiPathSearcher.new + end + + class ArbitrarySearcher < GemPathSearcher + def initialize(source_index) + @source_index = source_index + super() + end + + def init_gemspecs + @source_index.map { |_, spec| spec }.sort { |a,b| + (a.name <=> b.name).nonzero? || (b.version <=> a.version) + } + end + end + + class MultiPathSearcher + def initialize + @main_searcher = ArbitrarySearcher.new(MAIN_INDEX) + @fallback_searcher = ArbitrarySearcher.new(FALLBACK_INDEX) + end + + def find(path) + try = @main_searcher.find(path) + return try if try + @fallback_searcher.find(path) + end + + def find_all(path) + try = @main_searcher.find_all(path) + return try unless try.empty? + @fallback_searcher.find_all(path) + end + end + + class MultiSourceIndex + def search(*args) + try = MAIN_INDEX.search(*args) + return try unless try.empty? + FALLBACK_INDEX.search(*args) + end + + def find_name(*args) + try = MAIN_INDEX.find_name(*args) + return try unless try.empty? + FALLBACK_INDEX.find_name(*args) + end + end +end \ No newline at end of file diff --git a/spec/integration/merb/tasks/merb.thor/gem_ext.rb b/spec/integration/merb/tasks/merb.thor/gem_ext.rb new file mode 100644 index 0000000..61bd474 --- /dev/null +++ b/spec/integration/merb/tasks/merb.thor/gem_ext.rb @@ -0,0 +1,124 @@ +require "erb" + +Gem.pre_install_hooks.push(proc do |installer| + $INSTALLING << installer.spec + + unless File.file?(installer.bin_dir / "common.rb") + FileUtils.mkdir_p(installer.bin_dir) + FileUtils.cp(File.dirname(__FILE__) / "common.rb", installer.bin_dir / "common.rb") + end + + include ColorfulMessages + name = installer.spec.name + if $GEMS && versions = ($GEMS.assoc(name) || [])[1] + dep = Gem::Dependency.new(name, versions) + unless dep.version_requirements.satisfied_by?(installer.spec.version) + error "Cannot install #{installer.spec.full_name} " \ + "for #{$INSTALLING.map {|x| x.full_name}.join(", ")}; " \ + "you required #{dep}" + ::Thor::Tasks::Merb::Gem.rollback_trans + exit! + end + end + success "Installing #{installer.spec.full_name}" +end) + +class ::Gem::Uninstaller + def self._with_silent_ui + + ui = Gem::DefaultUserInteraction.ui + def ui.say(str) + puts "- #{str}" + end + + yield + + class << Gem::DefaultUserInteraction.ui + remove_method :say + end + end + + def self._uninstall(source_index, name, op, version) + unless source_index.find_name(name, "#{op} #{version}").empty? + uninstaller = Gem::Uninstaller.new( + name, + :version => "#{op} #{version}", + :install_dir => Dir.pwd / "gems", + :all => true, + :ignore => true + ) + _with_silent_ui { uninstaller.uninstall } + end + end + + def self._uninstall_others(source_index, name, version) + _uninstall(source_index, name, "<", version) + _uninstall(source_index, name, ">", version) + end +end + +Gem.post_install_hooks.push(proc do |installer| + $INSTALLING.pop + source_index = installer.instance_variable_get("@source_index") + ::Gem::Uninstaller._uninstall_others( + source_index, installer.spec.name, installer.spec.version + ) +end) + +class ::Gem::DependencyInstaller + alias old_fg find_gems_with_sources + + def find_gems_with_sources(dep) + if @source_index.any? { |_, installed_spec| + installed_spec.satisfies_requirement?(dep) + } + return [] + end + + old_fg(dep) + end +end + +class ::Gem::SpecFetcher + alias old_fetch fetch + def fetch(dependency, all = false, matching_platform = true) + idx = Gem::SourceIndex.from_installed_gems + + dep = idx.search(dependency).sort.last + + if dep + file = dep.loaded_from.dup + file.gsub!(/specifications/, "cache") + file.gsub!(/gemspec$/, "gem") + spec = ::Gem::Format.from_file_by_path(file).spec + [[spec, file]] + else + old_fetch(dependency, all, matching_platform) + end + end +end + +class ::Gem::Installer + def app_script_text(bin_file_name) + template = File.read(File.dirname(__FILE__) / "app_script.rb") + erb = ERB.new(template) + erb.result(binding) + end +end + +class ::Gem::Specification + def recursive_dependencies(from, index = Gem.source_index) + specs = self.runtime_dependencies.map do |dep| + spec = index.search(dep).last + unless spec + from_name = from.is_a?(::Gem::Specification) ? from.full_name : from.to_s + wider_net = index.find_name(dep.name).last + ThorUI.error "Needed #{dep} for #{from_name}, but could not find it" + ThorUI.error "Found #{wider_net.full_name}" if wider_net + ::Thor::Tasks::Merb::Gem.rollback_trans + end + spec + end + specs + specs.map {|s| s.recursive_dependencies(self, index)}.flatten.uniq + end +end \ No newline at end of file diff --git a/spec/integration/merb/tasks/merb.thor/main.thor b/spec/integration/merb/tasks/merb.thor/main.thor new file mode 100644 index 0000000..ea6438b --- /dev/null +++ b/spec/integration/merb/tasks/merb.thor/main.thor @@ -0,0 +1,150 @@ +require "rubygems" +require "rubygems/source_index" +require "rubygems/dependency_installer" +require "rubygems/uninstaller" +require "fileutils" +require File.join(File.dirname(__FILE__), "utils") +require File.join(File.dirname(__FILE__), "gem_ext") +require File.join(File.dirname(__FILE__), "ops") + +$INSTALLING = [] + +module Merb + + class Gem < Thor + extend ColorfulMessages + + def initialize + dirs = [Dir.pwd, File.dirname(__FILE__) / ".."] + root = dirs.find {|d| File.file?(d / "config" / "dependencies.rb")} + + if root + @depsrb = root / "config" / "dependencies.rb" + else + self.class.error "dependencies.rb was not found" + exit! + end + + FileUtils.mkdir_p(Dir.pwd / "gems") + + @list = Collector.collect(File.read(@depsrb)) + @idx = ::Gem::SourceIndex.new.load_gems_in("gems/specifications") + end + + def list + require "pp" + pp @list + end + + desc "redeploy", "Syncs up gems/cache with gems/gems. All gems in the cache " \ + "that are not already installed will be installed from the " \ + "cache. All installed gems that are not in the cache will " \ + "be uninstalled." + def redeploy + gem_dir = Dir.pwd / "gems" / "gems" + cache_dir = Dir.pwd / "gems" / "cache" + + gems = Dir[gem_dir / "*"].map! {|n| File.basename(n)} + cache = Dir[cache_dir / "*.gem"].map! {|n| File.basename(n, ".gem")} + new_gems = cache - gems + outdated = gems - cache + idx = ::Gem::SourceIndex.new + idx.load_gems_in(Dir.pwd / "gems" / "specifications") + + new_gems.each do |g| + installer = ::Gem::Installer.new(cache_dir / "#{g}.gem", + :bin_dir => Dir.pwd / "bin", + :install_dir => Dir.pwd / "gems", + :ignore_dependencies => true, + :user_install => false, + :wrappers => true, + :source_index => idx) + + installer.install + end + + outdated.each do |g| + /(.*)\-(.*)/ =~ g + name, version = $1, $2 + uninstaller = ::Gem::Uninstaller.new(name, + :version => version, + :bin_dir => Dir.pwd / "bin", + :install_dir => Dir.pwd / "gems", + :ignore => true, + :executables => true + ) + uninstaller.uninstall + end + end + + desc "confirm", "Confirm the current setup. merb:gem:install will " \ + "automatically run this task before committing the " \ + "changes it makes." + def confirm(gems = @list) + ::Gem.path.replace([Dir.pwd / "gems"]) + ::Gem.source_index.load_gems_in(Dir.pwd / "gems" / "specifications") + + self.class.info "Confirming configuration..." + + ::Gem.loaded_specs.clear + + begin + gems.each do |name, versions| + versions ||= [] + ::Gem.activate name, *versions + end + rescue ::Gem::LoadError => e + self.class.error "Configuration could not be confirmed: #{e.message}" + self.class.rollback_trans + end + self.class.info "Confirmed" + end + + desc 'install', 'Sync up your bundled gems with the list in config/dependencies.rb' + def install(*gems) + if gems.empty? + gems = @list + else + gems = gems.map {|desc| name, *versions = desc.split(" ") } + end + + $GEMS = gems + + self.class.begin_trans + + gems.each do |name, versions| + dep = ::Gem::Dependency.new(name, versions || []) + unless @idx.search(dep).empty? + next + end + + rescue_failures do + $INSTALLING = [] + _install(dep) + end + end + + gem_dir = Dir.pwd / "gems" / "gems" + installed_gems = Dir[gem_dir / "*"].map! {|n| File.basename(n)} + + list = full_list.map {|x| x.full_name}.compact + + (installed_gems - list).each do |g| + /^(.*)\-(.*)$/ =~ g + name, version = $1, $2 + uninstaller = ::Gem::Uninstaller.new(name, + :version => version, + :bin_dir => (Dir.pwd / "bin").to_s, + :install_dir => (Dir.pwd / "gems").to_s, + :ignore => true, + :executables => true + ) + uninstaller.uninstall + end + + confirm(gems) + + self.class.commit_trans + end + end +end \ No newline at end of file diff --git a/spec/integration/merb/tasks/merb.thor/ops.rb b/spec/integration/merb/tasks/merb.thor/ops.rb new file mode 100644 index 0000000..c758af2 --- /dev/null +++ b/spec/integration/merb/tasks/merb.thor/ops.rb @@ -0,0 +1,93 @@ +module Thor::Tasks + module Merb + class Collector + attr_reader :dependencies + + def self.collect(str) + collector = new + collector.instance_eval(str) + collector.dependencies + end + + def initialize + @dependencies = [] + end + + def dependency(name, *versions) + versions.pop if versions.last.is_a?(Hash) + @dependencies << [name, versions] + end + end + + class Gem < Thor + def full_list + @idx.load_gems_in("gems/specifications") + + @list.map do |name, versions| + dep = ::Gem::Dependency.new(name, versions) + spec = @idx.search(dep).last + unless spec + self.class.error "A required dependency #{dep} was not found" + self.class.rollback_trans + end + deps = spec.recursive_dependencies(dep, @idx) + [spec] + deps + end.flatten.uniq + end + + def rescue_failures(error = StandardError, prc = nil) + begin + yield + rescue error => e + if prc + prc.call(e) + else + puts e.message + puts e.backtrace + end + self.class.rollback_trans + end + end + + def self.begin_trans + note "Beginning transaction" + FileUtils.cp_r(Dir.pwd / "gems", Dir.pwd / ".original_gems") + end + + def self.commit_trans + note "Committing transaction" + FileUtils.rm_rf(Dir.pwd / ".original_gems") + end + + def self.rollback_trans + if File.exist?(Dir.pwd / ".original_gems") + note "Rolling back transaction" + FileUtils.rm_rf(Dir.pwd / "gems") + FileUtils.mv(Dir.pwd / ".original_gems", Dir.pwd / "gems") + end + exit! + end + + private + def _install(dep) + @idx.load_gems_in("gems/specifications") + return if @idx.search(dep).last + + installer = ::Gem::DependencyInstaller.new( + :bin_dir => Dir.pwd / "bin", + :install_dir => Dir.pwd / "gems", + :user_install => false) + + begin + installer.install dep.name, dep.version_requirements + rescue ::Gem::GemNotFoundException => e + puts "Cannot find #{dep}" + rescue ::Gem::RemoteFetcher::FetchError => e + puts e.message + puts "Retrying..." + retry + end + end + end + end +end \ No newline at end of file diff --git a/spec/integration/merb/tasks/merb.thor/utils.rb b/spec/integration/merb/tasks/merb.thor/utils.rb new file mode 100644 index 0000000..1b1caa6 --- /dev/null +++ b/spec/integration/merb/tasks/merb.thor/utils.rb @@ -0,0 +1,40 @@ +class String + def /(other) + (Pathname.new(self) + other).to_s + end +end + +module ColorfulMessages + + # red + def error(*messages) + puts messages.map { |msg| "\033[1;31m#{msg}\033[0m" } + end + + # yellow + def warning(*messages) + puts messages.map { |msg| "\033[1;33m#{msg}\033[0m" } + end + + # green + def success(*messages) + puts messages.map { |msg| "\033[1;32m#{msg}\033[0m" } + end + + alias_method :message, :success + + # magenta + def note(*messages) + puts messages.map { |msg| "\033[1;35m#{msg}\033[0m" } + end + + # blue + def info(*messages) + puts messages.map { |msg| "\033[1;34m#{msg}\033[0m" } + end + +end + +module ThorUI + extend ColorfulMessages +end