guard / guard-jasmine

The Swiss Army knife for automated Jasmine specs in your console.
http://guard.github.io/guard-jasmine
MIT License
303 stars 81 forks source link

Running guard-jasmine from command line doesn't run any specs #93

Closed CPDevbot closed 11 years ago

CPDevbot commented 11 years ago

I've set up spec/javascripts/spec.js.coffee and have one spec file with 3 tests in spec/javascripts. When I run jasmine within the browser, the 3 tests run.

When I run guard and it starts and runs guard-jasmine, it finds and runs all my tests, like so:

$ bundle exec guard
Guard uses GNTP to send notifications.
Guard is now watching at '/workpath'
Guard::Jasmine starts Unicorn test server on port 52512 in development environment.
Waiting for Jasmine test runner at http://localhost:52512/jasmine
Run all Jasmine suites
Run Jasmine suite at http://localhost:52512/jasmine

Finished in 0.013 seconds
3 specs, 0 failures
Done.

But, when I run guard-jasmine from the terminal, no specs are found:

$ guard-jasmine
Guard::Jasmine starts Unicorn test server on port 53307 in test environment.
Waiting for Jasmine test runner at http://localhost:53307/jasmine
Run all Jasmine suites
Run Jasmine suite at http://localhost:53307/jasmine

Finished in 0.001 seconds
0 specs, 0 failures
Done.

Guard::Jasmine stops server.

Any idea as to what I need to change to help the CLI runner find my specs?

Thanks.

netzpirat commented 11 years ago

Are you using the latest version of Guard::Jasmine? I'm asking because the the Guard output looks like version 1.4.0, so you may not have updated your gems to the latest version. Is there a difference when you run guard-jasmine with bundle exec?

itrigga commented 11 years ago

I'm experiencing this too - the relevant bits from my Gemfile.lock are:

guard (1.0.2)
  ffi (>= 0.5.0)
  thor (~> 0.14.6)

guard-jasmine (1.2.2)
  childprocess
  guard (>= 0.8.3)
  multi_json
  thor

jasminerice (0.0.10)
  coffee-rails
  haml
netzpirat commented 11 years ago

Please update your gems, guard-jasmine is at 1.10.1 and Guard at 1.5.4

itrigga commented 11 years ago

Hi,

OK, I've upped the gems, but the problem is still there:

bundle exec guard 14:01:15 - INFO - Guard uses TerminalTitle to send notifications. 14:01:15 - INFO - Guard is now watching at '/Users/aldavidson/projects/wms' 14:01:16 - INFO - Guard::Jasmine starts Unicorn test server on port 63243 in development environment. 14:01:17 - INFO - Waiting for Jasmine test runner at http://localhost:63243/jasmine 14:01:32 - INFO - Run all Jasmine suites 14:01:32 - INFO - Run Jasmine suite at http://localhost:63243/jasmine 14:01:36 - INFO - Finished in 0.018 seconds 14:01:36 - INFO - 3 specs, 0 failures

bundle exec guard-jasmine 14:01:57 - INFO - Guard::Jasmine starts Unicorn test server on port 63327 in test environment. 14:01:59 - INFO - Waiting for Jasmine test runner at http://localhost:63327/jasmine 14:02:13 - INFO - Run all Jasmine suites 14:02:13 - INFO - Run Jasmine suite at http://localhost:63327/jasmine 14:02:15 - INFO - Finished in 0 seconds 14:02:15 - INFO - 0 specs, 0 failures

netzpirat commented 11 years ago

Great. The problem is that it works fine on my current project, so I assume it's a configuration issue. The guard-jasmine command uses the test environment by default, whereas running it in Guard defaults to the development environment. You can see if the command works in development mode with:

bundle exec guard-jasmine -e development

If this works, then the specs are not working properly in the test environment. You could switch Guard to test, just to have the server started and open the specs in the browser for analysis.

guard :jasmine, :server_env => :test do
end
itrigga commented 11 years ago

Hmm, now that is strange - running in the development environment does work, just not in test.

Any ideas why that might be?

netzpirat commented 11 years ago

I guess the spec files aren't included, so it might be a Sprocket or Jasminerice configuration issue.

jcmuller commented 11 years ago

Great. Adding -e development solved the issue. Now, to understand why on test env they aren't found.

rahul commented 11 years ago

Adding -e development did not solve the issue for me.

I use jruby-1.6.7 and my Gemfile contains jaminerice, guard-jasmine (with the default Guardfile) in the :test, :development group

bundle exec guard-jasmine-debug picks up the test runner (localhost:3000/jasmine) automatically and prints a json of the tests run.

but the following does not work,

> bundle exec guard-jasmine -u http://localhost:3000/jasmine -e development
23:03:16 - INFO - Guard::Jasmine starts webrick test server on port 64231 in development environment.
23:03:31 - WARN - Timeout while waiting for the server startup. You may need to increase the `:server_timeout` option.
23:03:31 - INFO - Waiting for Jasmine test runner at http://localhost:3000/jasmine
23:03:31 - INFO - Run all Jasmine suites
23:03:31 - INFO - Run Jasmine suite at http://localhost:3000/jasmine
23:03:34 - ERROR - An error occurred: Unable to access Jasmine specs at http://localhost:3000/jasmine
23:03:34 - INFO - Guard::Jasmine stops server.

but I can see that the test runner (@ localhost:3000) served the jasmine/index.haml page to guard-jasmine,

Started HEAD "/jasmine" for 127.0.0.1 at 2012-12-07 23:06:19 +0530
Processing by Jasminerice::SpecController#index as */*
  Rendered /Users/rahul/.rvm/gems/jruby-1.6.7/gems/jasminerice-0.0.10/app/views/jasminerice/spec/index.html.haml (108.0ms)
Completed 200 OK in 132ms (Views: 132.0ms)

Started GET "/jasmine" for 0:0:0:0:0:0:0:1%0 at 2012-12-07 23:06:20 +0530
Processing by Jasminerice::SpecController#index as HTML
  Rendered /Users/rahul/.rvm/gems/jruby-1.6.7/gems/jasminerice-0.0.10/app/views/jasminerice/spec/index.html.haml (130.0ms)
Completed 200 OK in 176ms (Views: 175.0ms)
netzpirat commented 11 years ago

@rahul When passing the url with the -u option, then you must use a fixed port, otherwise the port will not match:

bundle exec guard-jasmine -p 3000 -u http://localhost:3000/jasmine -e development

The default port number is randomly picked to avoid port collision for multiple spec runs on a CI server.

jcmuller commented 11 years ago

So, the mistery of the different results boiled down to different environments being used. Now, to fix the test environment, I added config.assets.debug = true.

rahul commented 11 years ago

@netzpirat That doesn't work (and gives the same output). I ran guard-jasmine with the additional -p parameter and a console.log of options @ lib/guard/jasmine/phantomjs/guard-jasmine.js +70 which gave

{"url":"http://localhost:3000/jasmine","timeout":10000,"specdoc":"always","focus":true,"console":"failure","errors":"failure"}

Am I looking at the wrong place here because the port is not part of the options?

netzpirat commented 11 years ago

@rahul The port is only used to start the server, the PhantomJS script only retrieves the final url where request the Jasmine spec.

rahul commented 11 years ago

@netzpirat Okay. So I have my development server running @ http://localhost:3000, the test runner @ http://localhost:3000/jasmine. I ran guard-jasmine as follows,

bundle exec guard-jasmine -e development -p 3001 -u http://localhost:3000/jasmine

and the got the same output,

01:57:29 - INFO - Guard::Jasmine starts webrick test server on port 3001 in development environment.
01:57:44 - WARN - Timeout while waiting for the server startup. You may need to increase the `:server_timeout` option.
01:57:44 - INFO - Waiting for Jasmine test runner at http://localhost:3000/jasmine
01:57:45 - INFO - Run all Jasmine suites
01:57:45 - INFO - Run Jasmine suite at http://localhost:3000/jasmine
01:57:47 - ERROR - An error occurred: Unable to access Jasmine specs at http://localhost:3000/jasmine
01:57:47 - INFO - Guard::Jasmine stops server.
netzpirat commented 11 years ago

@rahul I'm very sorry, but just from the log snippet I cannot see the problem. Since I cannot reproduce it, I can't have a look at the environment and do some debugging.

rahul commented 11 years ago

@netzpirat Here are a couple of confusing and interesting points I came across after a few hours of debugging.

  1. guard-jasmine picks up test runners on any port except 3000. Also, there seems to be no need to mention the environment (-e). You can run guard-jasmine with something like "guard-jasmine -u test_url" and leaving out '-e' (which runs the tests in test environment even when my test runner ran in development environment).
  2. guard-jasmine-debug picks up test runners on port 3000 by default.

Unfortunately I could not figure out the reason for such different behaviours, but I will try again sometime soon, and if you have any hunches about this, do let me know so that I can test them out.

Thanks, Rahul

netzpirat commented 11 years ago

@rahul Yes, the environment is optional, as most settings have default values. You can see them with guard-jasmine help spec:

$ guard-jasmine help spec
Usage:
  guard-jasmine spec

Options:
  -s, [--server=SERVER]                # Server to start, either `auto`, `webrick`, `mongrel`, `thin`, `unicorn`, `jasmine_gem` or `none`
                                       # Default: auto
  -p, [--port=N]                       # Server port to use
  -e, [--server-env=SERVER_ENV]        # The server environment to use, for example `development`, `test` etc.
                                       # Default: test
      [--server-timeout=N]             # The number of seconds to wait for the Jasmine spec server
                                       # Default: 15
  -c, [--rackup-config=RACKUP_CONFIG]  # The rackup config to use (jasminerice only)
  -b, [--bin=BIN]                      # The location of the PhantomJS binary
  -d, [--spec-dir=SPEC_DIR]            # The directory with the Jasmine specs
                                       # Default: spec/javascripts
  -u, [--url=URL]                      # The url of the Jasmine test runner
  -t, [--timeout=N]                    # The maximum time in seconds to wait for the spec runner to finish
                                       # Default: 10
      [--console=CONSOLE]              # Whether to show console.log statements in the spec runner, either `always`, `never` or `failure`
                                       # Default: failure
      [--errors=ERRORS]                # Whether to show errors in the spec runner, either `always`, `never` or `failure`
                                       # Default: failure
  -f, [--focus]                        # Specdoc focus to hide successful tests when at least one test fails
                                       # Default: true
      [--specdoc=SPECDOC]              # Whether to show successes in the spec runner, either `always`, `never` or `failure`
                                       # Default: always

I have no problems running the specs on port 3000, but since it's the default Rails server port, it may be used by another Rails app in the background. The following example is the spec suite from Haml_Coffee_Assets:

$ guard-jasmine -p 3000 -u http://localhost:3000/jasmine
23:04:37 - INFO - Guard::Jasmine starts Unicorn test server on port 3000 in test environment.
23:04:37 - INFO - Waiting for Jasmine test runner at http://localhost:3000/jasmine
23:04:39 - INFO - Run all Jasmine suites
23:04:39 - INFO - Run Jasmine suite at http://localhost:3000/jasmine
23:04:40 - INFO - Finished in 0.008 seconds
23:04:40 - INFO - HAML
23:04:40 - INFO -   .escape
23:04:40 - INFO -     ✔ escapes an ampersand
23:04:40 - INFO -     ✔ escapes the less than sign
23:04:40 - INFO -     ✔ escapes the greater than sign
23:04:40 - INFO -     ✔ escapes a double quote
23:04:40 - INFO -     ✔ escapes a single quote
23:04:40 - INFO -   .cleanValue
23:04:40 - INFO -     ✔ returns an empty string for null
23:04:40 - INFO -     ✔ returns an empty string for undefined
23:04:40 - INFO -     ✔ marks a boolean true with unicode character u0093
23:04:40 - INFO -     ✔ marks a boolean true with unicode character u0093
23:04:40 - INFO -     ✔ passes everything else unchanged
23:04:40 - INFO -   .extend
23:04:40 - INFO -     ✔ extends the given object from a source object
23:04:40 - INFO -     ✔ extends the given object from multipe source objects
23:04:40 - INFO -     ✔ overwrites existing properties
23:04:40 - INFO -   .globals
23:04:40 - INFO -     ✔ retuns the global object
23:04:40 - INFO -     ✔ returns an empty object
23:04:40 - INFO -   .context
23:04:40 - INFO -     ✔ merges the locals into the globals
23:04:40 - INFO -   .preserve
23:04:40 - INFO -     ✔ preserves all newlines
23:04:40 - INFO -   .findAndPreserve
23:04:40 - INFO -     ✔ replaces newlines within the preserved tags
23:04:40 - INFO -   .surround
23:04:40 - INFO -     ✔ surrounds the text to the function result
23:04:40 - INFO -   .succeed
23:04:40 - INFO -     ✔ appends the text to the function result
23:04:40 - INFO -   .precede
23:04:40 - INFO -     ✔ prepends the text to the function result
23:04:40 - INFO - 21 specs, 0 failures
23:04:40 - INFO - Done.
23:04:40 - INFO - Guard::Jasmine stops server.

guard-jasmine-debug is meant as a low level debug tool to get the JSON protocol output from the PhantomJS runner. You normally don't use it directly, I use it in seldom cases to have more debug info for certain issues. It does not start a server and used its own set of default values. There's nothing wrong with this.

I'm closing this issue since the CLI runner works fine and it's likely a configuration issue (and @CPJenkins doesn't participate in his own issue). Please feel free to open a question at StackOverflow for getting usage help. I'm monitoring the guard tag and will try to help you sort the issue out.

jcmuller commented 11 years ago

Thanks, @netzpirat. I was impersonating mistakingly @CPJenkins when I created the issue. Tried to remove the issue but I couldn't so I just let it progress and I made comments as myself from then on.

netzpirat commented 11 years ago

Ah great, thanks for the hint!