jejacks0n / teaspoon

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

Error: Sprockets::Rails::Helper::AssetFilteredError #197

Closed samu closed 9 years ago

samu commented 10 years ago

After generating the initial teaspoon files, i get this error when i try to run rake teaspoon:

Error: Sprockets::Rails::Helper::AssetFilteredError: Asset filtered out and will not be served: 
add `Rails.application.config.assets.precompile += %w( teaspoon.css )` to `config/initializers/assets.rb` and restart your server

I have to add several lines such as

Rails.application.config.assets.precompile += %w( teaspoon.css )

to an initializer file in order to successfully run the specs.

jejacks0n commented 10 years ago

Can you explain why you have dev/test set to precompile -- or why you want to include teaspoon in production?

GetContented commented 10 years ago

I have the same issue. Using Rails 4.1.0 I don't think either of us want to include it in production. I'm using guard and guard teaspoon. I just upgraded my app from 3.2.x (latest) to 4.1.0.

jejacks0n commented 10 years ago

Hmm.. I've used teaspoon with rails 4.1.0. @jayzes did you have this issue?

jayzes commented 10 years ago

I didn't, no. What does your Gemfile look like?

GetContented commented 10 years ago

Here's my gemfile

source 'https://rubygems.org'
ruby "2.1.1"

gem 'rails', '4.1.0'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'pg' # postgres
# to update ember using this version of ember-rails: rails generate ember:install --head
gem 'ember-rails'
gem 'ember-source', '1.5.0'
gem 'ember-data-source', '1.0.0.beta.7'
gem "fog", "~> 1.3.1" # for Amazon S3
gem 'mail_form'
gem 'newrelic_rpm'

gem 'sass-rails', '~> 4.0.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby
gem 'jquery-rails', '= 3.0.3'
gem 'jquery-ui-rails'
gem 'carrierwave'
gem 'paper_trail', '~>3.0.1'
gem 'devise'
gem 'seed-fu', '~> 2.3.0'
gem 'pundit'
# gem 'thin'
gem 'foreman' # instead of thin, use foreman and puma (precursor to rubinius)
gem 'puma'
gem 'rack-timeout' # also for puma - coz it doesn't "get back" properly otherwise
#  see: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

group :development, :test do
  gem 'qunit-rails', '>= 0.0.6'
  gem 'yui-rails'
  gem 'rspec-rails', '>= 2.11.4'
  gem "teaspoon"
  gem 'guard'
  gem 'rb-readline' # required for guard to work properly on OS/X
  gem 'rb-fsevent' # required for guard
  gem 'jasmine-rails'
  gem 'jasmine-jquery-rails' # custom jasmine jquery matchers
  gem 'guard-jasmine'
  gem 'guard-teaspoon'
  gem 'guard-rspec', '~> 3.0'
  gem "minitap", "~> 0.5"
  gem "phantomjs", ">= 1.8.1.1"
end

group :test do
  gem 'rspec-instafail'
  gem 'factory_girl'
  gem 'factory_girl_rails'
  gem 'database_cleaner', '>= 1.2'
end

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.7'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'
GetContented commented 10 years ago

Quesiton... did you use a fresh Rails 4.1 install to test against? or were you using an upgraded one, because this is apparently the standard Rails 4.1 environments/test.rb file: (which I am using)

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.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

  # Do not eager load code on boot. This avoids loading your whole application
  # just for the purpose of running a single test. If you are using a tool that
  # preloads Rails for running tests, you may have to set it to true.
  config.eager_load = false

  # Configure static asset server for tests with Cache-Control for performance.
  config.serve_static_assets  = true
  config.static_cache_control = 'public, max-age=3600'

  # Show full error reports and disable caching.
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Raise exceptions instead of rendering exception templates.
  config.action_dispatch.show_exceptions = 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

  # Print deprecation notices to the stderr.
  config.active_support.deprecation = :stderr

  # Raises error for missing translations
  # config.action_view.raise_on_missing_translations = true

  config.ember.variant = :development
end

(note I've added the config.ember.variant bit on the end because I'm using ember)

jejacks0n commented 10 years ago

can you do me a favor and put this in your teaspoon_env and report back on what it says.

puts "!Env: #{Rails.env}:#{RAILS_ENV}"

Technically speaking, the engine will run in development when you browse to /teaspoon (since that's the server that's running), and should normally be in development from the CLI, but I want to confirm.

jejacks0n commented 10 years ago

Having them both run in development actually simplifies a lot of the differences that exist with configuration like this.

GetContented commented 10 years ago

Hm... I hope not, because I'd be wanting to use a different DB in test vs development! Yeah, sure, though, I'll go print out the env and report back.

GetContented commented 10 years ago

It said this:

> [#] uninitialized constant RAILS_ENV

So I took out the errant constant and then it said this:

!Env: development:
Starting the Teaspoon server...
Puma 2.8.2 starting...
* Min threads: 0, max threads: 16
* Environment: test
* Listening on tcp://0.0.0.0:61667

then errored as before.

GetContented commented 10 years ago

I don't understand how if it's running in development environment, it manages to still use the test database?

GetContented commented 10 years ago

Oh... sorry I'm silly, I just got totally confused between rspec running and teaspoon because guard drives them both... god what a noob error.

GetContented commented 10 years ago

So yeah, interestingly, Puma is running as the server, and it's running in test, whereas Rails.env says development.

jejacks0n commented 10 years ago

Hmm.. Ok, so if I'm not mistaken, you have test using precompiled assets? Correct me if I'm wrong.

samu commented 10 years ago

Here's my (rather simple) Gemfile:

source 'https://rubygems.org'

gem 'rails', '4.1.0'

gem 'pg'

gem 'sass-rails', '~> 4.0.3'

gem 'uglifier', '>= 1.3.0'

gem 'coffee-rails', '~> 4.0.0'

gem 'haml'

gem 'haml-rails'

gem 'jquery-rails'

gem 'turbolinks'

gem 'jbuilder', '~> 2.0'

gem 'sdoc', '~> 0.4.0', group: :doc

gem 'spring', group: :development

gem 'minitest-rails', '2.0.0.beta1'

gem "teaspoon", :path => '~/Development/teaspoon'

When i originally opened this issue, i was using 0.7.9. I'm now pointing to a local clone of the master branch. The error message slightly changed:

Error: ActionView::Template::Error: Asset filtered out and will not be served: ...

I'm not trying to run in production nor am i precompiling assets. I'm simply running rake teaspoon, which runs in development mode.

GetContented commented 10 years ago

@jejacks0n Not that I know of, and if I am, then it's not on purpose. AFAIK I'm using the standard generated environments/test.rb file aside from my slight addition of ember stuff. I didn't consciously do anything to have test use precompiled assets. Can you point me to some specific places where I can either find out about this or give me some way to change it, or provide me with what an ideal environments/test.rb file should be such that teaspoon works?

If it doesn't work straight "out of the box", shouldn't there be some indication about what to change to make it work in the teaspoon documentation?

GetContented commented 10 years ago

Guh... so I've been re-reading the asset pipeline guides just now and I found this, which is probably our issue by the sound of it:

Rails 4 no longer sets default config values for Sprockets in test.rb, so test.rb now requires Sprockets configuration. The old defaults in the test environment are: config.assets.compile = true, config.assets.compress =
false, config.assets.debug = false and config.assets.digest = false.

That seems like a kind of strange thing to put in as a "default". "Hey kids, it's up to you... so much for convention over configuration... bye".

I'm going to go and twiddle the settings and see if I can't get it working. Will report back if/when I get it working.

GetContented commented 10 years ago

Okay that didn't immediately fix it, but then I remembered teaspoon is running in dev mode, not test... even though my server is running in test (guh?) so I tried setting my test.rb so it had this in it:

  config.assets.compile = true
  config.assets.compress = false
  config.assets.debug = false
  config.assets.digest = false

and then running this:

RAILS_ENV=test rake teaspoon

and it worked fine.

So then I looked in my environments/development.rb file and realised it didn't have those settings either, so I tried just wacking them in to see if that fixed the default teaspoon run and it did.

I'm not really sure why puma is running in a different env than teaspoon and it strikes me as being something pretty crap, but it obviously isn't really anything to do with teaspoon because teaspoon is behaving just fine.

So the problem was the standard rails environments/development.rb file now doesn't work straight up out of the box with teaspoon.

It's probably worth mentioning this in the documentation somewhere, IMHO.

And by the way, thanks very much for making Teaspoon. It's freaking awesome. :) <3

jejacks0n commented 10 years ago

Thanks for identifying the issue.. I also noticed that in another issue on guard-teaspoon you're using 0.7.9. Wondering if this is different in 0.8. Can you update to what's on master and let me know -- removing the fix you put in? I would appreciate the help since I'm kinda bogged down in other work.

GetContented commented 10 years ago

@jejacks0n Yeah I noticed the difference, but seeing as it hadn't propagated to the official gem servers I thought it was just alpha or not ready for primetime at least.

So I tried what you asked, and I got this: (I'm using qunit as well as jasmine for some tests because I'm halfway through migrating between them).

TeaspoonError: QUnit not found -- use `suite.use_framework :qunit` and adjust or remove the `suite.javascripts` directive.
  # teaspoon-qunit.js:1302
  # teaspoon-qunit.js:1408

I'm kinda like you at the moment, I don't really have time to spend on this either unfortunately.

jejacks0n commented 10 years ago

Fair enough. to fix that you need to follow the instructions for updating.. I broke some things on purpose to make it better for the long run. Just run the install generator again and make whatever changes you made.

rails g teaspoon:install --framework=qunit

GetContented commented 10 years ago

@jejacks0n ah right... the process outlined in "upgrading". Sorry that wasn't very clear to me from which versions to which versions it was talking about.

I think this line under 0.8.0 follow-ups / todos was what threw me:

Here's a short list of things that 0.8.0 might also address.

(because it sounds like 0.8.0 hasn't happened yet, so I wasn't sure which versions "upgrading" was talking about).

Anyway, I'll try again later today. Thanks heaps.

samu commented 10 years ago

@jejacks0n @JulianLeviston Thanks for your investigations. I tried to include those four lines Julian pointed out in the development.rb, without success. What works for me to fix the error is using this in the dev env:

config.assets.raise_runtime_errors = false

More about it here.

I don't fully understand the deal with runtime error checking, but i don't think setting this to false in order to make the teaspoon specs execute is the right approach. Would it make sense to use a separate environment configuration just for teaspoon?

GetContented commented 10 years ago

Hey @jejacks0n ... so I tried to update again, but it keeps complaining that:

TeaspoonError: Jasmine not found -- use `suite.use_framework :jasmine` and adjust or remove the `suite.javascripts` directive.
  # teaspoon-jasmine.js:1158
  # teaspoon-jasmine.js:1339

I'm pretty sure that the reason is going to be that I'm using jasmine-rails so it can't seem to see jasmine because it appears to need to load jasmine and teaspoon-jasmine before it loads all the asset stuff, and I couldn't seem to work out how to put version 2 (which I'm using) in... seems to need to use 1.3.1 (ie there's a disparity between these two config options, the second of which I couldn't work out how to specify 2.0 in:

    suite.use_framework :jasmine, "2.0.0"

and

    #suite.javascripts = ["jasmine/1.3.1", "teaspoon-jasmine"]

I went through and re-config'd everything. Man... it's a lot of configuration.

I just don't have hours to throw at this... so I'm going to revert for now.

GetContented commented 10 years ago

Okay I'm going to have another crack at this...

GetContented commented 10 years ago

Okay I've been trying to work this out for ages. It keeps saying

TeaspoonError: Jasmine not found -- use `suite.use_framework :jasmine` and adjust or remove the `suite.javascripts` directive

I've tried various configurations of the use_framework and the suite.javascripts settings. At the moment suite.javascripts is commented out and the only three lines I have in the default suite are below... have I missed something obvious?

The only thing I have in my suite is this:

    suite.use_framework :jasmine, "2.0.0"
    suite.matcher = "{spec/javascripts,app/assets}/**/*_spec.{js,js.coffee,coffee}"
    suite.helper = "spec_helper"

I feel like I'm somehow idiotic or I'm doing something really stupid.

GetContented commented 10 years ago

Okay I got it pushed past this point... the thing that wasn't working was that I didn't have suite.javascripts supplied, so obviously it wasn't loading jasmine before teaspoon-jasmine.js, which is a hard requirement on that file that it's loaded first...

In the past when I'd tried to use this, I had a weird reticence towards including something with 1.3.1 in its version given that I'm NOT using 1.3.1 - that REALLY confused me. Is it supposed to be like that?

So I "fixed" it by uncommenting this:

suite.javascripts = ["jasmine/1.3.1", "teaspoon-jasmine"]

This was totally non-obvious to me.

GetContented commented 10 years ago

Okay the next "gotcha" for me was the fact that I'd left my spec_helper.js.coffee file in situ as my spec helper assuming teaspoon would just pick it up (because it's a bit automagic and lovely), but the auto-generated spec_helper.js was taking precedence. I completely missed that, and I really shouldn't have. This was just plain old fashioned stupidiy on my part. I noted that support/bind-poly is required, so I put that into my spec_helper.coffee.js and removed the default generated spec_helper.js file.

This now got me running again. Huzzah!

Okay, so I'm at this point where I'd really like teaspoon to run in the test rails env. Is it possible to add this a CLI option to guard, or am I just barking up the wrong tree? I know I should use fixtures, etc. But when it comes to full stack integration tests (and I do need some of these), I really need to touch the rails app with my javascript code and I just can't do that without being in test env.

The other reason is I don't particularly want to turn my asset alerts off in my dev env and also until I've got this issue I've got sorted with the faster-json-generating-OJ gem and teaspoon not working, I want to box teaspoon into the test env.

GetContented commented 10 years ago

Okay so the final issue I have around this (you're probably hating me right about now, aren't you?)... is when I save a file, guard-teaspoon kicks in (I updated it to point to the latest git version rather than the gem version because I wasn't 100% sure it wasn't just a version-mismatch thing)... but then it seems to be giving teaspoon the wrong number of arguments.

15:56:16 - ERROR - Guard::Teaspoon failed to achieve its <run_on_modifications>, exception was:
> [#] ArgumentError: wrong number of arguments (2 for 0..1)
> [#] /Users/julian/.rvm/gems/ruby-2.1.1@rails3/gems/teaspoon-0.8.0/lib/teaspoon/console.rb:20:in `execute'

Apologies in advance if this is just me being stupid. I hope not. Could you maybe shed some light?

Note that this is only when I'm saving a file, not when it's running all the specs.

samu commented 10 years ago

@JulianLeviston i had the same problem, check out modeset/guard-teaspoon#29

GetContented commented 10 years ago

@samu oh yay I'm not an idiot :) I wonder why the modeset guys hadn't already picked this up as part of their general use of teaspoon. Also, I wonder why they didnt see the problems we were seeing with the debug mode on rails 4.1 already. Ah well :)

gvarela commented 10 years ago

@jejacks0n I just ran into this issue on a fresh Rails 4.1 app. Resetting the compile flags fixed the issue.

  config.assets.compile = true
  config.assets.compress = false
  config.assets.debug = false
  config.assets.digest = false

When I get a chance I will try to dig in and see why latest Rails 4 changed the behavior.

jejacks0n commented 10 years ago

I think this might be cleaned up / fixed. Let me know if that's not the case.

delwaterman commented 10 years ago

Brand new install with Rails 4.1, following step-by-step install instructions, get the same issue here.

jejacks0n commented 10 years ago

Could be how the instrumentation hooks into sprockets. Or more likely an issue in sprockets-rails directly?


Jeremy Jackson

On Jul 28, 2014, at 5:53 AM, Orion Delwaterman notifications@github.com wrote:

Brand new install with Rails 4.1, following step-by-step install instructions, get the same issue here.

— Reply to this email directly or view it on GitHub.

samu commented 10 years ago

Have you tried using the master branch? And, for a quick dirty fix to get going, you could try setting the following configuration in development.rb:

config.assets.raise_runtime_errors = false

sporto commented 10 years ago

Some issue here, using Rails 4.1 and master branch of teaspoon.

Teaspoon gem is only loaded in dev / test:

group :development, :test do
    ...
    gem 'teaspoon',            github: 'modeset/teaspoon'
end

Assets settings are just as default installation on development.rb and test.rb

Getting:

Asset filtered out and will not be served: add `Rails.application.config.assets.precompile += %w( teaspoon.css )` to `config/initializers/assets.rb` and restart your server

Adding this to initializers/assets fixes it:

Rails.application.config.assets.precompile += %w( teaspoon.css )
Rails.application.config.assets.precompile += %w( teaspoon-teaspoon.js )
GetContented commented 10 years ago

Yeah I retried, and had the same issue.

jabr commented 10 years ago

I'm seeing the same problems with the current teaspoon master. The only thing that works for me is to use spring teaspoon. The current guard-teaspoon doesn't work, either, even with a cmd: 'spring teaspoon' option.

appletonwebb commented 10 years ago

Vanilla Rails 4.2beta1 app, followed the installation instructions, running bin/rake teaspoon gives:

Error: ActionView::Template::Error: Asset filtered out and will not be served: add `Rails.application.config.assets.precompile += %w( teaspoon.css )` to `config/initializers/assets.rb` and restart your server
appletonwebb commented 10 years ago

I should also add that adding the following to confing/environments/test.rb:

config.assets.compile = true
config.assets.compress = false
config.assets.debug = false
config.assets.digest = false

and running:

RAILS_ENV=test bin/bundle exec teaspoon

works. If that's the right way to set-up and run teaspoon shouldn't it be added to the documentation? Otherwise, could you please suggest the right way to set-up and run it for a 4.1+ Rails app?

Thank you!

liseki commented 10 years ago

Since a quick web search lead me here and the above discussion points at a few places, here's to those who come behind me.

In Rails 4.1 development mode, the asset pipeline now checks for whether or not an asset you reference in a template would actually be available in production (see https://github.com/rails/sprockets-rails/pull/84). If the asset has not been declared for pre-compilation, it throws the aforementioned AssetFilteredError exception. This was done to help those who have been bit by missing assets in production. This can be turned off in the appropriate environment file using:

config.assets.raise_runtime_errors = false

Be conscious of what you are giving up by doing that! If you only compile your assets into application.js and application.css, and one or two other files then you should be fine. However if you are juggling numerous assets files, having it on may be useful.

With that said, I think the appropriate solution is to add the particular assets files to the pre-compilation list. Since I do not want these files in production, I have the following in initializers/assets.rb:

unless Rails.env.production?
  Rails.application.config.assets.precompile += %w( teaspoon.css teaspoon-teaspoon.js jasmine/1.3.1.js teaspoon-jasmine.js )
end

I am using jasmine, so edit the list according to your testing framework. I think this is the best way to handle this in the meantime until it is perhaps handled by the gem in the future.

Thanks to the devs for teaspoon!

jejacks0n commented 10 years ago

Yup, we identified it a few weeks back, but haven't put in a proper fix for it. I need to experiment a bit to make sure it works nicely for all javascript/css files that could be used.

ballPointPenguin commented 10 years ago

same problem here in virgin Rails 4.1.5 app. Thank you, @liseki that fix seems reasonable and works for me.

grantgeorge commented 9 years ago

I was able to fix this error by adding

Rails.application.config.assets.precompile += %w(
  teaspoon.css
  teaspoon-teaspoon.js
  teaspoon-jasmine.js
  # other assets
)

to config/initializers/assets.rb

jejacks0n commented 9 years ago

Confirmed this is fixed in master (with some minor tweaks), and will be included in the next release.

ccallebs commented 8 years ago

After installing a fresh version I'm still getting this issue.

Gem versions

teaspoon (1.1.1)
teaspoon-jasmine (2.3.4)

Everything else is in place from the install, except for removing

#= require application

from spec_helper.coffee.

wanchic commented 8 years ago

Using teaspoon without coffee-script, I too am getting these errors.

Gem versions

teaspoon 1.1.1
teaspoon-jasmine 2.3.4
sprockets 3.5.2

I discovered that the issue stems from this upgrade:

-    sprockets-rails (2.3.3)
-      actionpack (>= 3.0)
-      activesupport (>= 3.0)
-      sprockets (>= 2.8, < 4.0)
+    sprockets-rails (3.0.0)
+      actionpack (>= 4.0)
+      activesupport (>= 4.0)
+      sprockets (>= 3.0.0)

As long as sprockets-rails is kept at 2.3.3, you should be fine. v3.0.0 seems to conflict at the moment.

Hope this helps (^_^)

jejacks0n commented 8 years ago

https://github.com/modeset/teaspoon/issues/443