jejacks0n / teaspoon

Teaspoon: Javascript test runner for Rails. Use Selenium, BrowserStack, or PhantomJS.
1.43k stars 243 forks source link

Cannot use teaspoon because it's assuming config/environment will always be present. #371

Closed jejacks0n closed 9 years ago

jejacks0n commented 9 years ago

I have a micro rails application -- with my development application defined in a simple config.ru file.

require "rubygems"
require "bundler/setup"
require "action_controller/railtie"
require "sprockets/railtie"

Bundler.require

module Micro
  class Application < Rails::Application
    config.session_store :cookie_store, :key => "_app_session"
    config.secret_token = "[token]"
    config.active_support.deprecation = :log
    config.consider_all_requests_local = true
    config.encoding = "utf-8"
    config.eager_load = false

    config.assets.enabled = true
    config.assets.version = "1.0"
    config.assets.debug = true

    config.assets.paths = []
    config.assets.paths << "lib/vendor"
    config.assets.paths << "lib/javascripts"
    config.assets.paths << "lib/stylesheets"
  end
end

class ApplicationController < ActionController::Base
  prepend_view_path Rails.application.root.join('examples')

  def page
    render template: params[:page] || 'index'
  end
end

Rails.application.initialize!
Rails.application.routes.draw do
  # rendering pages
  match '/(:page)' => 'application#page', via: :get
end

run Micro::Application rescue nil

I then put a teaspoon_env.rb in the spec directory, as per the standard -- and require rails in it:

unless defined?(Rails) # Set RAILS_ROOT and load the environment.
  ENV['RAILS_ROOT'] = File.expand_path("..", __FILE__)
  load File.expand_path("../../config.ru", __FILE__)
end

Teaspoon.configure do |config|
  config.mount_at = "/teaspoon"
  config.root = nil
  config.asset_paths = ["spec/javascripts", "spec/javascripts/stylesheets"]
  config.fixture_paths = ["spec/javascripts/fixtures"]

  config.suite do |suite|
    suite.use_framework :mocha
  end
end

This simple setup no longer works because internally to teaspoon, it's making assumptions about how rails is setup in pathing and file structures. This seems like a negative thing to tie teaspoon to, and makes it feel more coupled to rails than desired.

/usr/local/opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/teaspoon-1.0.2/lib/teaspoon/environment.rb:56:in `require': cannot load such file -- /Users/jejacks0n/Projects/mathhoops/config/environment (LoadError)
jejacks0n commented 9 years ago

I'm not sure what the best approach here is, but I've used this setup before and it provides some useful tooling that is otherwise still kind of a shit show with grunt and friends. Coffeescript, sass, slim (or haml etc.), and rake tasks to build javascripts etc. This takes me about 2 minutes to setup, and I kinda wrote teaspoon to allow for these simplistic setups that I personally enjoy.

I'm wondering if we just continue on if unable to find the standard rails environment, and let it fail over if rails is still undefined after locating/loading the teaspoon env?

jejacks0n commented 9 years ago

For the record, I view this a little bit like a more familiar middleman development pipeline.

jejacks0n commented 9 years ago

I'm using 0.9 in the interim -- I couldn't find a simple/good fix.