Fixtures not loading properly? #4

Closed
jondkinney opened this Issue Sep 4, 2013 · 18 comments

Comments

Projects
None yet
10 participants
@jondkinney

I'm trying to get fixtures working, but having issues.

In my gemfile (in the development & test group):

gem 'jasmine-rails'
gem 'jasmine-jquery-rails'

I have the following folder structure:

My fixture: /spec/javascripts/fixtures/order_form.html

Jasmine Spec Helper: /spec/javascripts/helpers/spec_helper.coffee

in my spec_helper.coffee

#=require jquery
#=require jasmine-jquery

Things seem to be loading

screen shot 2013-09-03 at 10 46 55 pm

But the test fails with a 404 fixture file now found.

jasmine_fixture_failure

If I go into the error I am presented with the following error on the 404 itself:

<h1>Routing Error</h1>
<p><pre>No route matches [GET] &quot;/spec/javascripts/fixtures/order_form.html&quot;</pre></p>
<p>
  Try running <code>rake routes</code> for more information on available routes.
</p>

I've also tried adding this to my spec_helper.coffee (though I'm not sure why this would be required).

jasmine.getFixtures().fixturesPath = 'assets/fixtures'

And while it made the 404 go away, the spec doesn't pass like it should because I still don't think the fixture is being loaded properly. I say this because it's un-modified code from Railscasts that I know should pass. I'm just trying to test to make sure everything is wired up properly!

My spec/javascripts/support/jasmine.yml file is very minimal per the suggestion of https://github.com/searls/jasmine-rails#asset-pipeline-support

# minimalist jasmine.yml configuration when leveraging asset pipeline
spec_files:
  - "**/*[Ss]pec.{js,coffee}"

Any help would be greatly appreciated!

@jondkinney

This comment has been minimized.

Show comment Hide comment
@jondkinney

jondkinney Sep 5, 2013

So I ended up just using jasmine-fixtures instead. However, this is still a problem that probably should be fixed. I'm happy to help so I'll leave this open.

So I ended up just using jasmine-fixtures instead. However, this is still a problem that probably should be fixed. I'm happy to help so I'll leave this open.

@wndxlori

This comment has been minimized.

Show comment Hide comment
@wndxlori

wndxlori Sep 24, 2013

I'm experiencing this problem now. Any assistance would be appreciated.

I'm experiencing this problem now. Any assistance would be appreciated.

@jondkinney

This comment has been minimized.

Show comment Hide comment
@jondkinney

jondkinney Sep 25, 2013

@wndxlori I never found a solution unfortunately. I just switched to using jasmine-fixtures instead. Hopefully someone will come along that can get this sorted...

@wndxlori I never found a solution unfortunately. I just switched to using jasmine-fixtures instead. Hopefully someone will come along that can get this sorted...

@ChristopherWerby

This comment has been minimized.

Show comment Hide comment
@ChristopherWerby

ChristopherWerby Sep 29, 2013

Giving a bump to this problem because I'm having exactly the same issue. Rails 3.2.11. I'm using a more expansive jasmine.yml file than the original poster -- mine comes almost exactly from the jasmine documentation -- but I've tried the minimal version too with no luck. Jasmine-fixtures doesn't seem to be a solution for me, because I'm trying to test json server returns.

I read the previous closed issue which involved jasmine-rice. I'm not using jasmine-rice. I'm using the gem 'jasmine-rails' followed by gem 'jasmine-jquery-rails', and gem 'sinon-rails'. (gem 'jquery-rails' is above in my gemfile.) I pulled the sinon rails gem as a test, but it didn't resolve the issue.

Giving a bump to this problem because I'm having exactly the same issue. Rails 3.2.11. I'm using a more expansive jasmine.yml file than the original poster -- mine comes almost exactly from the jasmine documentation -- but I've tried the minimal version too with no luck. Jasmine-fixtures doesn't seem to be a solution for me, because I'm trying to test json server returns.

I read the previous closed issue which involved jasmine-rice. I'm not using jasmine-rice. I'm using the gem 'jasmine-rails' followed by gem 'jasmine-jquery-rails', and gem 'sinon-rails'. (gem 'jquery-rails' is above in my gemfile.) I pulled the sinon rails gem as a test, but it didn't resolve the issue.

@wndxlori

This comment has been minimized.

Show comment Hide comment
@wndxlori

wndxlori Oct 2, 2013

Christopher, you might also be interested in https://github.com/pivotal/jasmine-ajax

I almost started using that, but in the end, jasmine-fixtures did the job, although I really would have preferred to continue to use jasmine-jquery-rails fixtures.

wndxlori commented Oct 2, 2013

Christopher, you might also be interested in https://github.com/pivotal/jasmine-ajax

I almost started using that, but in the end, jasmine-fixtures did the job, although I really would have preferred to continue to use jasmine-jquery-rails fixtures.

@ChristopherWerby

This comment has been minimized.

Show comment Hide comment
@ChristopherWerby

ChristopherWerby Oct 2, 2013

Thank you, Lori!

I'll check it out.

It's driving me crazy though that I can't figure out the issue. I'm sure that it must be some configuration detail that I've missed.

Best,

Christopher Werby
Pipsqueak Productions, LLC
http://www.Pipsqueak.com

On Oct 1, 2013, at 8:07 PM, Lori M Olson notifications@github.com wrote:

Christopher, you might also be interested in https://github.com/pivotal/jasmine-ajax

I almost started using that, but in the end, jasmine-fixtures did the job, although I really would have preferred to continue to use jasmine-jquery-rails fixtures.


Reply to this email directly or view it on GitHub.

Thank you, Lori!

I'll check it out.

It's driving me crazy though that I can't figure out the issue. I'm sure that it must be some configuration detail that I've missed.

Best,

Christopher Werby
Pipsqueak Productions, LLC
http://www.Pipsqueak.com

On Oct 1, 2013, at 8:07 PM, Lori M Olson notifications@github.com wrote:

Christopher, you might also be interested in https://github.com/pivotal/jasmine-ajax

I almost started using that, but in the end, jasmine-fixtures did the job, although I really would have preferred to continue to use jasmine-jquery-rails fixtures.


Reply to this email directly or view it on GitHub.

@travisjeffery

This comment has been minimized.

Show comment Hide comment
@travisjeffery

travisjeffery Oct 2, 2013

Owner

Hey y'all there was a bug in the pipeline that was fixed in v3.2.13. Upgrade Rails to v3.2.13 and it's fixed. There's no problem with this gem.

Owner

travisjeffery commented Oct 2, 2013

Hey y'all there was a bug in the pipeline that was fixed in v3.2.13. Upgrade Rails to v3.2.13 and it's fixed. There's no problem with this gem.

@jondkinney

This comment has been minimized.

Show comment Hide comment
@jondkinney

jondkinney Oct 2, 2013

@travisjeffery I was running either Rails 3.2.13 or 3.2.14 when I filed this issue.

@travisjeffery I was running either Rails 3.2.13 or 3.2.14 when I filed this issue.

@travisjeffery

This comment has been minimized.

Show comment Hide comment
@travisjeffery

travisjeffery Oct 2, 2013

Owner

find the exact rails version. same with ruby.

clone this and see if it works for you: https://github.com/travisjeffery/jasmine-jquery-rails-issue-4

Owner

travisjeffery commented Oct 2, 2013

find the exact rails version. same with ruby.

clone this and see if it works for you: https://github.com/travisjeffery/jasmine-jquery-rails-issue-4

@lazylester

This comment has been minimized.

Show comment Hide comment
@lazylester

lazylester Dec 1, 2013

I'm seeing the same problem... fixture not found. Using Rails4. Error message is:
ActionController::RoutingError (No route matches [GET] "/spec/javascripts/fixtures/home_fixture.html")

How does Rails know that this is not a route to be interpreted but a file to be loaded (like an asset?).

I tried the jasmine-jquery-rails-issue-4 app and it works, but I couldn't get it working under Rails4.

Under Rails4 the 'rake jasmine' task for jasmine-jquery-rails-issue-4 can't be found. I haven't figured out why.

I'm seeing the same problem... fixture not found. Using Rails4. Error message is:
ActionController::RoutingError (No route matches [GET] "/spec/javascripts/fixtures/home_fixture.html")

How does Rails know that this is not a route to be interpreted but a file to be loaded (like an asset?).

I tried the jasmine-jquery-rails-issue-4 app and it works, but I couldn't get it working under Rails4.

Under Rails4 the 'rake jasmine' task for jasmine-jquery-rails-issue-4 can't be found. I haven't figured out why.

@randoum

This comment has been minimized.

Show comment Hide comment
@randoum

randoum Dec 3, 2013

I come with a temporary solution that works well for me. While waiting for a better solution

I am using a standard installation with

  • rails 4.0.1
  • jasmine-rails 0.5.0
  • jasmine-jquery-rails 1.5.9

The idea is to mount the directory spec/javascripts/fixtures through the routes.rb file to give jasmine access to fixture files through the /spec/javascripts/fixtures URI

Create an initializer, ex /initializers/jasmine_fixtures.rb

# Map fixtures directory for Jasmine suite
if defined?(Jasmine::Jquery::Rails::Engine)
  JasmineFixtureServer = Proc.new do |env|
    Rack::Directory.new('spec/javascripts/fixtures').call(env)
  end
end

Part of route.rb

  # Mount Jasmine engine
  mount JasmineRails::Engine => '/specs' if defined?(JasmineRails)

  # mount spec/javascripts/fixtures directory
  mount JasmineFixtureServer => '/spec/javascripts/fixtures' if defined?(Jasmine::Jquery::Rails::Engine)

randoum commented Dec 3, 2013

I come with a temporary solution that works well for me. While waiting for a better solution

I am using a standard installation with

  • rails 4.0.1
  • jasmine-rails 0.5.0
  • jasmine-jquery-rails 1.5.9

The idea is to mount the directory spec/javascripts/fixtures through the routes.rb file to give jasmine access to fixture files through the /spec/javascripts/fixtures URI

Create an initializer, ex /initializers/jasmine_fixtures.rb

# Map fixtures directory for Jasmine suite
if defined?(Jasmine::Jquery::Rails::Engine)
  JasmineFixtureServer = Proc.new do |env|
    Rack::Directory.new('spec/javascripts/fixtures').call(env)
  end
end

Part of route.rb

  # Mount Jasmine engine
  mount JasmineRails::Engine => '/specs' if defined?(JasmineRails)

  # mount spec/javascripts/fixtures directory
  mount JasmineFixtureServer => '/spec/javascripts/fixtures' if defined?(Jasmine::Jquery::Rails::Engine)
@lazylester

This comment has been minimized.

Show comment Hide comment
@lazylester

lazylester Dec 3, 2013

yes that works, Randoum, thank you very much.

A tiny bit simpler still is to mount the JasmineFixtureServer at "spec/javascripts/fixtures", as this is the default fixture path. Then you don't have to include the "beforeEach" statement.

I can imagine that your approach could be included in the jasmine-jquery-rails engine as a permanent solution but I wasn't able to figure out how to do it.

yes that works, Randoum, thank you very much.

A tiny bit simpler still is to mount the JasmineFixtureServer at "spec/javascripts/fixtures", as this is the default fixture path. Then you don't have to include the "beforeEach" statement.

I can imagine that your approach could be included in the jasmine-jquery-rails engine as a permanent solution but I wasn't able to figure out how to do it.

@randoum

This comment has been minimized.

Show comment Hide comment
@randoum

randoum Dec 3, 2013

Yes off course, assign the path at your convenience. I updated my previous comment to make it clearer for the next persons that would be looking for this solution. Can you please verify/confirm it's correct cause I did not test it like this.

I tried as well to mount the path from jasmine-jquery-rails engine, but I know nothing about Rails engines :) Let's wait for a skilled guy to pass-by

randoum commented Dec 3, 2013

Yes off course, assign the path at your convenience. I updated my previous comment to make it clearer for the next persons that would be looking for this solution. Can you please verify/confirm it's correct cause I did not test it like this.

I tried as well to mount the path from jasmine-jquery-rails engine, but I know nothing about Rails engines :) Let's wait for a skilled guy to pass-by

@lazylester

This comment has been minimized.

Show comment Hide comment
@lazylester

lazylester Dec 3, 2013

Yes, Randoum, you have it correct. Thanks again.

Yes, Randoum, you have it correct. Thanks again.

sgharms pushed a commit to pocket-gophers-2014/zombify that referenced this issue May 24, 2014

Steven G. Harms
Egregious hack to get Jasmine-Jquery fixtures working
Carolyn and I worked for a bit on Friday trying to
get the fixtures to be seen per the specification
in jasmine-jquery-rails.  We were unsuccessful.
It appears that the issue is that the fixtures
path is not made available on the web server.

This was listed as a bug here:

travisjeffery/jasmine-jquery-rails#4

The solution, implemented here, is to define a new
Rack middleware in an initializer
(`JasmineFixtureServer`) which serves assets out
of the physical file directory
`spec/javascripts/fixtures`.

We then `mount` that engine at the URL path of
`spec/javascripts/fixtures`.  Thus we can "serve"
our fixtures (yay).

This seems like a bug to me on jquery-rails, but
this will keep things going.
@Trevoke

This comment has been minimized.

Show comment Hide comment
@Trevoke

Trevoke Jun 25, 2014

So.. Is this how we should set up loading fixtures from now on?

Trevoke commented Jun 25, 2014

So.. Is this how we should set up loading fixtures from now on?

@nathany nathany referenced this issue in searls/jasmine-rails Jul 8, 2014

Closed

Unable to run Jasmine tests with fixtures #123

@codener

This comment has been minimized.

Show comment Hide comment
@codener

codener Apr 22, 2015

@randoum, thanks a lot! Your approach got me running.

Just want to note that I'm not using jasmine-jquery-rails, but jasmine-jquery. By changing if defined?(Jasmine::Jquery::Rails::Engine) to if defined?(JasmineRails), I made it work for my stack.

codener commented Apr 22, 2015

@randoum, thanks a lot! Your approach got me running.

Just want to note that I'm not using jasmine-jquery-rails, but jasmine-jquery. By changing if defined?(Jasmine::Jquery::Rails::Engine) to if defined?(JasmineRails), I made it work for my stack.

@adamphillips

This comment has been minimized.

Show comment Hide comment
@adamphillips

adamphillips May 14, 2015

We had the same problem. We also wanted to be able to import application styles for particular components into the fixture styles so that if they were changed in a way that broke the component, the tests would fail. We also wanted to be able to use the less css compiler in our fixture styles.

Building on @randoum's idea above, we set up a Sprockets environment and mounted that. The basic result uses the same changes to routes.rb but the initializer looks something like this

# Setup Sprockets environment for serving Jasmine fixtures
JasmineFixtureServer = Sprockets::Environment.new

JasmineFixtureServer.append_path 'app/assets/stylesheets'
JasmineFixtureServer.append_path 'spec/javascripts/fixtures'

JasmineFixtureServer.logger = Rails.logger

# Copy over the less configuration from the application
JasmineFixtureServer.context_class.class_eval do
  class_attribute :less_config
  self.less_config = Rails.application.config.less
end

We had the same problem. We also wanted to be able to import application styles for particular components into the fixture styles so that if they were changed in a way that broke the component, the tests would fail. We also wanted to be able to use the less css compiler in our fixture styles.

Building on @randoum's idea above, we set up a Sprockets environment and mounted that. The basic result uses the same changes to routes.rb but the initializer looks something like this

# Setup Sprockets environment for serving Jasmine fixtures
JasmineFixtureServer = Sprockets::Environment.new

JasmineFixtureServer.append_path 'app/assets/stylesheets'
JasmineFixtureServer.append_path 'spec/javascripts/fixtures'

JasmineFixtureServer.logger = Rails.logger

# Copy over the less configuration from the application
JasmineFixtureServer.context_class.class_eval do
  class_attribute :less_config
  self.less_config = Rails.application.config.less
end

@ananyo2012 ananyo2012 referenced this issue in publiclab/plots2 Jul 6, 2016

Closed

Work in Progress - Jasmine test #603

2 of 6 tasks complete
@Xiaohong-Deng

This comment has been minimized.

Show comment Hide comment
@Xiaohong-Deng

Xiaohong-Deng Aug 14, 2017

@randoum Your workaround is still needed in Aug. 2017 for Rails 4.2.6. Thanks.

@randoum Your workaround is still needed in Aug. 2017 for Rails 4.2.6. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment