jejacks0n / teaspoon

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

Visit pages using PhantomJS directly when writing specs with TeaSpoon - Jasmine #331

Closed ingolfured closed 9 years ago

ingolfured commented 9 years ago

I'm trying to write a Javascript spec for my Rails 3.2 application using Teaspoon (the Jasmine version). I'm trying to write a spec that does something like this

describe("Fun", function() {
    var page = require('webpage').create() //ERROR

    it("should be so much fun", function() {
        page.open('/pageToTest/')
        expect($('#HereIsTheParty')).not.toBe( undefined );
    });
});

However, require('webpage') doesn't run (Error: Module name "system" has not been loaded yet for context) even though the Requirejs gem has been installed and can be accessed from the Chrome console.

My question is, can I easily get require('webpage') to run using Rails or should I be using something else? Is it maybe easier to just use Capybara since so far I've been using

describe "Fun", :type => :feature do
    it "should be so much fun" do
        visit '/pageToTest/'
        expect(page).to have_content 'Success'
    end
end

without any problems. I would however prefer using pure Javascript since in this case it's more convenient. What do you guys think? Thanks!

(Copied my question from stackoverflow.com (http://stackoverflow.com/questions/28968231/visit-pages-using-phantomjs-directly-when-writing-specs-with-teaspoon-jasmine)

jejacks0n commented 9 years ago

Answered on stack overflow. Something like cucumber or capybara+rspec works better for these sorts of things.

jejacks0n commented 9 years ago

so, secretly, you can do this by making an ajax request to your endpoint and inserting that into the fixture element, but this is not advisable.

ingolfured commented 9 years ago

Sorry for late reply. Thanks for this mate! Didnt really understand what was going on. I think Ill just stick with Capybara for feature tests.

Best, Ingo

On Wed, Mar 11, 2015 at 4:45 PM, Jeremy Jackson notifications@github.com wrote:

so, secretly, you can do this by making an ajax request to your endpoint and inserting that into the fixture element, but this is not advisable.

— Reply to this email directly or view it on GitHub https://github.com/modeset/teaspoon/issues/331#issuecomment-78303244.

jejacks0n commented 9 years ago

Yup, no worries.. teaspoon is primarily for unit testing javascript -- with some integration level things by the nature of what javascript usually does and how that intersects with what we typically consider integration tests. It's advisable to do unit tests for javascript, in a scenario that you can run against various browsers potentially (using selenium-webdriver you can accomplish this).

Anyway, javascript unit specs are blazingly fast in comparison to capybara/cucumber/etc and allow you to cover more cases without having to have a unique integration feature for each one, and is just another layer for you to utilize for good coverage and good speed.