Permalink
Browse files

Test Rails integration with Cucumber

  • Loading branch information...
1 parent 4fd147d commit 1ef339ab5fa3d27b831e2e5b36ad48ac5170fdba @iain committed Jul 13, 2012
View
@@ -3,3 +3,5 @@
Gemfile.lock
pkg/*
.rvmrc
+log/*.log
+tmp/
View
@@ -3,4 +3,11 @@ require "bundler/gem_tasks"
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
-task :default => :spec
+require 'cucumber/rake/task'
+Cucumber::Rake::Task.new(:cucumber)
+
+Cucumber::Rake::Task.new(:wip, "Run features tagged with @wip") do |t|
+ t.profile = "wip"
+end
+
+task :default => [:spec, :cucumber, :wip]
View
@@ -0,0 +1,2 @@
+default: --format progress --strict --tags ~@wip
+wip: --format pretty --wip --tags @wip
@@ -0,0 +1,12 @@
+Feature: Rails Integration
+
+ To use http_accept_language inside a Rails application, just add it to your
+ Gemfile and run `bundle install`.
+
+ It is automatically added to your middleware.
+
+ Scenario: Installing
+ When I generate a new Rails app
+ And I add http_accept_language to my Gemfile
+ And I run `bundle exec rake middleware`
+ Then the output should contain "use HttpAcceptLanguage::Middleware"
View
@@ -0,0 +1,13 @@
+When /^I generate a new Rails app$/ do
+ @aruba_io_wait_seconds = 10
+ app_name = "foobar"
+ # install rails with as few things as possible, for speed!
+ run_simple "bundle exec rails new #{app_name} --skip-git --skip-active-record --skip-sprockets --skip-javascript --skip-test-unit --old-style-hash"
+ cd app_name
+end
+
+When /^I add http_accept_language to my Gemfile$/ do
+ # Specifiy a path so cucumber will use the unreleased version of the gem
+ path = File.expand_path('../../../', __FILE__)
+ append_to_file "Gemfile", "gem 'http_accept_language', :path => '#{path}'"
+end
@@ -0,0 +1 @@
+require 'aruba/cucumber'
@@ -21,4 +21,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rspec'
s.add_development_dependency 'rack-test'
s.add_development_dependency 'guard-rspec'
+ s.add_development_dependency 'rails', '>= 3.2.6'
+ s.add_development_dependency 'cucumber'
+ s.add_development_dependency 'aruba'
end
@@ -1,3 +1,4 @@
+require 'http_accept_language/version'
require 'http_accept_language/parser'
-require 'http_accept_language/rack'
-require 'http_accept_language/rails' if defined?(ActionPack)
+require 'http_accept_language/middleware'
+require 'http_accept_language/railtie' if defined?(Rails::Railtie)
@@ -1,5 +1,5 @@
module HttpAcceptLanguage
- class Rack
+ class Middleware
def initialize(app)
@app = app
@@ -1,27 +0,0 @@
-require 'forwardable'
-
-module HttpAcceptLanguage
- module Rails
-
- extend Forwardable
-
- def http_accept_language
- @http_accept_language_parser ||= Parser.new(env['HTTP_ACCEPT_LANGUAGE'])
- end
-
- def_delegators :http_accept_language_parser,
- :user_preferred_languages, :user_preferred_languages=,
- :preferred_language_from, :compatible_language_from,
- :sanitize_available_locales, :language_region_compatible_from
-
- end
-
-end
-
-classes = if ActionPack::VERSION::MAJOR == 2
- [ActionController::Request, ActionController::CgiRequest]
- else
- [ActionDispatch::Request]
- end
-
-classes.each { |c| c.send :include, HttpAcceptLanguage::Rails }
@@ -0,0 +1,9 @@
+module HttpAcceptLanguage
+ class Railtie < ::Rails::Railtie
+
+ initializer "http_accept_language.add_middleware" do |app|
+ app.middleware.use Middleware
+ end
+
+ end
+end
@@ -23,7 +23,7 @@ def call(env)
def app
Rack::Builder.new do
- use HttpAcceptLanguage::Rack
+ use HttpAcceptLanguage::Middleware
run TestRackApp.new
end.to_app
end
View
@@ -1,37 +0,0 @@
-require 'http_accept_language'
-
-module ActionPack
- module VERSION
- MAJOR = 3
- end
-end
-
-module ActionDispatch
- class Request
- end
-end
-
-module ActionController
- class CgiRequest
- end
- class Request
- end
-end
-
-describe "Rails integration" do
-
- it "should be included into actionpack v2" do
- stub_const("ActionPack::VERSION::MAJOR", 2)
- load "http_accept_language/rails.rb"
-
- ActionController::Request.ancestors.should include HttpAcceptLanguage::Rails
- ActionController::CgiRequest.ancestors.should include HttpAcceptLanguage::Rails
- end
-
- it "should be included into actionpack v3" do
- stub_const("ActionPack::VERSION::MAJOR", 3)
- load "http_accept_language/rails.rb"
- ActionDispatch::Request.ancestors.should include HttpAcceptLanguage::Rails
- end
-
-end

1 comment on commit 1ef339a

Collaborator

grosser commented on 1ef339a Jul 13, 2012

this breaks rails 2 support ?
nevermind, just saw the docs!

Please sign in to comment.