Skip to content

Commit

Permalink
Fix test helpers due to internal sprockets changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseppstein committed Jul 28, 2011
1 parent 455fe5f commit 8757c37
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ gemspec
gem "rails", :git => "git://github.com/rails/rails.git", :branch => "3-1-stable"
gem "sfl", "~> 2.0"
gem "sprockets"
gem "mocha"

# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
Expand Down
35 changes: 18 additions & 17 deletions test/sass_rails_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@ class SassRailsTest < Sass::Rails::TestCase
assert_not_output(/conflict/)
end
end
test "scss template has correct dasherized css class for namespaced controllers" do
within_rails_app "scss_project" do
runcmd "rails generate controller foo/bar"
assert_file_exists "app/assets/stylesheets/foo/bar.css.scss"
assert_match /\.foo-bar/, File.read("app/assets/stylesheets/foo/bar.css.scss")
end
end
test "sass template has correct dasherized css class for namespaced controllers" do
within_rails_app "sass_project" do
runcmd "rails generate controller foo/bar"
assert_file_exists "app/assets/stylesheets/foo/bar.css.sass"
assert_match /\.foo-bar/, File.read("app/assets/stylesheets/foo/bar.css.sass")
end
end
# DISABLED because we've removed the feature for now.
# test "scss template has correct dasherized css class for namespaced controllers" do
# within_rails_app "scss_project" do
# runcmd "rails generate controller foo/bar"
# assert_file_exists "app/assets/stylesheets/foo/bar.css.scss"
# assert_match /\.foo-bar/, File.read("app/assets/stylesheets/foo/bar.css.scss")
# end
# end
# test "sass template has correct dasherized css class for namespaced controllers" do
# within_rails_app "sass_project" do
# runcmd "rails generate controller foo/bar"
# assert_file_exists "app/assets/stylesheets/foo/bar.css.sass"
# assert_match /\.foo-bar/, File.read("app/assets/stylesheets/foo/bar.css.sass")
# end
# end
test "templates are registered with sprockets" do
assert_equal Sass::Rails::SassTemplate, Sprockets.engines[".sass"]
assert_equal Sass::Rails::ScssTemplate, Sprockets.engines[".scss"]
Expand All @@ -61,9 +62,9 @@ class SassRailsTest < Sass::Rails::TestCase
end
test "sass asset paths work" do
css_output = sprockets_render("scss_project", "application.css.scss")
assert_match css_output, %r{asset-path:\s*"/assets/rails.png"}
assert_match css_output, %r{asset-url:\s*url\(/assets/rails.png\)}
assert_match css_output, %r{image-url:\s*url\(/assets/rails.png\)}
assert_match css_output, %r{asset-path:\s*"/assets/rails.png"}, 'asset-path:\s*"/assets/rails.png"'
assert_match css_output, %r{asset-url:\s*url\(/assets/rails.png\)}, 'asset-url:\s*url\(/assets/rails.png\)'
assert_match css_output, %r{image-url:\s*url\(/assets/rails.png\)}, 'image-url:\s*url\(/assets/rails.png\)'
end
test "css compressor compresses" do
assert_equal "div{color:red}\n", Sass::Rails::CssCompressor.new.compress(<<CSS)
Expand Down
28 changes: 22 additions & 6 deletions test/support/sass_rails_test_case.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'fileutils'
require 'tmpdir'
require 'sprockets/helpers/rails_helper'


class Sass::Rails::TestCase < ActiveSupport::TestCase

Expand Down Expand Up @@ -31,18 +33,20 @@ module TestAssetPaths
attr_accessor :assets
end

def sprockets_render(project, filename)
def fake_sprockets_env(project)
# Fuck everything about this.
# This HAS to get simplified.
# But it works right now.
env = Sprockets::Environment.new
env.context_class.extend(Sass::Rails::Railtie::SassContext)
env.context_class.sass_config = Sass::Rails::Railtie.config.sass
env.context_class.class_eval do
def self.assets=(assets)
@assets = assets
end
def self.assets
@assets
end
def self.sass_config
Sass::Rails::Railtie.config.sass
end
def config
@config ||= ActiveSupport::InheritableOptions.new
end
Expand All @@ -58,8 +62,20 @@ def asset_paths_with_testing
alias_method_chain :asset_paths, :testing
end
env.context_class.assets = env
env.paths << fixture_path("#{project}/app/assets/stylesheets")
env[filename].to_s
app = mock
app.stubs(:assets).returns(env)
config = ActiveSupport::InheritableOptions.new
config.sass = Sass::Rails::Railtie.config.sass
config.assets = env
config.assets.stubs(:prefix).returns("/assets")
app.stubs(:config).returns(config)
Rails.stubs(:application).returns(app)
env.append_path(fixture_path("#{project}/app/assets/stylesheets"))
env
end

def sprockets_render(project, filename)
fake_sprockets_env(project)[filename].to_s
end

def assert_file_exists(filename)
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require "rails/test_help"
require 'sass/rails'
require 'sfl'
require 'mocha'

Rails.backtrace_cleaner.remove_silencers!

Expand Down

0 comments on commit 8757c37

Please sign in to comment.