testdouble / jasmine-rails

A Jasmine runner for rails projects that's got you covered in both the terminal and the browser
http://rubygems.org/gems/jasmine-rails
MIT License
378 stars 154 forks source link

Working fixtures #180

Closed kot-begemot closed 8 years ago

kot-begemot commented 8 years ago

I made some effort to make sure that jasmine-jquery is able to fetch fixtures during the tests. This solution also works with phantomJS.

So, an example. Suppose, jasmine config has that

# spec/javascripts/support/jasmine.yml
... 
helpers:
  - "helpers/jasmine-jquery.js"

fixtures_preload:
  - "print-map.html"

And say you have a following test

// spec/javascripts/specs/print_map.js
//= require map/print
describe("Print map", function () {
    var map;

    beforeEach(function () {
        loadFixtures('print-map.html');
        map = $('.map'),
        spyOn(window, 'print');
    });

    it("should print with map", function () {
        map.addClass('dont-print');
        print_with_map.click();
        expect(window.print).toHaveBeenCalled();
        expect(map.hasClass('dont-print')).toBeFalsy();
    });
});

Then fixturesd will be properly served both in browser at localhost:3000/spec and in console with bundle exec rake spec:javascript

kot-begemot commented 8 years ago

Let me know if that looks uninteresting to you, I'll gonna fix tests then.

searls commented 8 years ago

Yeah, I'd actually ask you to add a new test for this because I'll never use it myself and I don't want to break it.

As for the new fixtures_preload key in the YAML, I'd ask you to check two things for us:

  1. Does the official jasmine gem or teaspoon gem have an existing name for an analogous/identical property? If so, use that.
  2. Do other Sprocketsy tools have an existing convention around use of pre/post that you're attempting to use? If not, I'd rather you just name it html_fixtures, or, if they are specific to jasmine-jquery in their utility, then jasmine_jquery_fixtures for abundant clarity that it's "proprietary" to that plugin.
kot-begemot commented 8 years ago

Hey, I fixed tests. They are passing now.

Another thing is renaming new key to html_fixtures. This is actually specific for PhantomJS. Thing is - in order to run test on CI, rake generates an HTML file and places that in tmp folder. Then it runs PhatomJS providing it with a path to generated html file. PhantomJS then includes HTML fixtures using a relative path. When running through browser there is a rails app, that can be requested, but for PhantomJS case, html fixtures should be there prerendered already. The idea is similar to assets_precompile concept.

Anyways, I added a test coverage for it as well.

kot-begemot commented 8 years ago

@searls so any feedback?

searls commented 8 years ago

Sorry I haven't gotten feedback to you yet, the truth of it is:

  1. I don't remember merging in support for jasmine-jquery fixtures in the first place because I've always been :-1: on actually using them (explanation here: http://searls.testdouble.com/posts/2011-12-11-jasmine-fixtures.html )
  2. This adds more to the repo than I'm comfortable blindly merging (rspec-mocks? 15 affected files?), but at the same time I've never used this feature and am not eager to support it, so I keep coming back to this thread without the energy needed to thoroughly review it.

I don't know where that leaves us, to be honest. I have a todo to find the time to look at this issue but it may be a while, I'm afraid.

searls commented 8 years ago

After previewing some of the changes in Sprockets 4 yesterday, I'm deciding to deprecate what (already apparently broken) fixture file support this gem has, with plans to eventually remove it. It's not a feature I recommend folks use in the vast majority of cases and it adds complexities I'd rather not maintain.

Thanks for working on this, but I recommend you keep your fork alive if you need this functionality.