Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zeus throwing errors when running RSpec

I'm running in to a situation which seems to happen to many users of Zeus and RSpec.

Let's say I have the following spec:

# spec/views/messages/show.html.erb

require 'spec_helper'

describe "messages/show.html.erb" do
  it "displays the text attribute of the message" do
    render
    rendered.should contain("Hello world!")
  end
end

and the following view template that it tests.

# app/views/messages/show.html.erb

Hello world!

My pwd is the root of the rails app. When I run rspec I get the following response:

user@host $ rspec
.

Finished in 0.06264 seconds
1 example, 0 failures

Randomized with seed 9609

Everything looks good. If, however, I run the test with zeus rspec spec (zeus rspec doesn't work at all) I get the following output.

user@host $ zeus rspec spec
.

Finished in 0.07292 seconds
1 example, 0 failures

Randomized with seed 0

F

Failures:

  1) messages/show.html.erb displays the text attribute of the message
     Failure/Error: render
     NameError:
       undefined local variable or method `render' for <RSpec::Core::ExampleGroup::Nested_2:0x936a0fc>
     # ./spec/views/show.html.erb_spec.rb:5:in `block (2 levels) in <top (required)>'
     # -e:1:in `<main>'

Finished in 0.00041 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/views/show.html.erb_spec.rb:4 # messages/show.html.erb displays the text attribute of the message

I have seen several questions similar to this on SO, such as these:

Zeus fails when testing with Rspec

zeus rspec fails include required files, but rspec alone does fine

Zeus + FactoryGirl::Syntax::Methods. undefined method `create'

The common thread is that the solution suggests commenting out / deleting the following lines from spec_helper.rb if they exist.

require 'rspec/autorun'
require 'rspec/autotest'

My problem is that those lines don't appear in my spec_helper.rb file or anywhere else in the application.

After some digging I found the offending line was actually in the rspec executable script in the RSpec gem.

I am currently using RSpec version 2.13.1 and the content of the file is as follows:

#!/usr/bin/env ruby

begin
  require 'rspec/autorun'
rescue LoadError
  $stderr.puts <<-EOS
#{'*'*50}
  Could not find 'rspec/autorun'

  This may happen if you're using rubygems as your package manager, but it is not
  being required through some mechanism before executing the rspec command.

  You may need to do one of the following in your shell:

    # for bash/zsh
    export RUBYOPT=rubygems

    # for csh, etc.
    set RUBYOPT=rubygems

  For background, please see http://gist.github.com/54177.
#{'*'*50}
  EOS
  exit(1)
end

It appears from the RSpec documentation that it is a convenience method that will run your tests for you. Strangely enough, when I comment out the require 'rspec/autorun' section of the begin/rescue zeus still has the same behavior (throwing the error), but rspec no longer functions in the traditional fashion (just running the rspec command). As per this documentation (https://www.relishapp.com/rspec/rspec-core/docs/command-line) you can still run it, just in that slightly more verbose fashion.

In any case, this hints to me that either zeus is either relying on a file other than the rspec exec script or the problem isn't quite as clearly related to just the spec_helper.rb require statements (which rspec 2.13.1 doesn't add to the config).

Has anyone run in to this situation or come down this same path??

I'm hesitant to throw up a an issue on either the rspec-rails / rspec-core or zeus repos as I'm not at all sure which library is causing problems for which.

Any help at all would be extremely appreciated.

like image 307
jamesconant Avatar asked Jun 07 '13 17:06

jamesconant


1 Answers

According to this you should follow specs files naming convention when doing view specs. Try to rename:

spec/views/messages/show.html.erb

to

spec/views/messages/show.html.erb_spec.rb

and it might help.

like image 194
pawurb Avatar answered Nov 04 '22 10:11

pawurb