I’m new in using RSpec and I can’t figured out to spec this controller
action.
class OrdersController < ApplicationController
before_filter :authenticate_user!
def index
respond_with(@orders = current_user.orders)
end
end
When I want to spec this “@assets = Asset.all” I use “Asset.stub(:all)
{ [mock_asset] }” as I read in the RSpec book but with
“current_user.orders” I don’t know how to do.
NB: I’m using Rails 3.0.0.rc2 and RSpec 2.0.0.beta.20
When I want to spec this “@assets = Asset.all” I use “Asset.stub(:all)
{ [mock_asset] }” as I read in the RSpec book but with
“current_user.orders” I don’t know how to do.
NB: I’m using Rails 3.0.0.rc2 and RSpec 2.0.0.beta.20
Not sure what I must have bumped, but autotest won’t run any specs–only
features. No errors are given on startup. I’ve taken “export
AUTOFEATURE=true” out of my ./bashrc file–now I just get a blank screen
when running autotest. Adding “export RSPEC=true” to .bashrc doesn’t
change anything either.
~/.autotest
require ‘autotest/growl’
Autotest.add_hook(:initialize) { |at|
at.add_exception %r{^.git} # ignore Version Control System
at.add_exception %r{^./tmp} # ignore temp files, lest autotest will
run again, and again…
at.clear_mappings # take out the default (test/test*rb)
Right. That’s because there is no current_user in the example, it’s in
the controller. Make sense? So you need to stub current_user in the
controller as well:
user = double(‘user’)
controller.stub(:current_user) { user }
user.stub(:orders) { [mock_order] }
Strange…that does work, but now autotest seems caught in an infinite
loop. When I run autospec, the specs run, then the features, then the
features again…and again…and again…and so on. If I run autotest
as follows: “AUTOFEATURE=false autotest”, I don’t have the problem. Any
other ideas?
Get rid of ‘Autotest.add_discovery { “rails” }’ from ./autotest/discover.rb.
I’ve seen this happen when files are generated during a spec run. What’s in spec/spec.opts and cucumber.yml?
No spec.opts file, and just the default cucumber.yml file (I believe):
If any of the gems listed in the Gemfile have :path or :git options, you need to run “bundle exec autotest”.
HTH,
DavidStrange…that does work, but now autotest seems caught in an infinite loop. When I run autospec, the specs run, then the features, then the features again…and again…and again…and so on. If I run autotest as follows: “AUTOFEATURE=false autotest”, I don’t have the problem. Any other ideas?
And now (I haven’t touched anything…seriously!), even “AUTOFEATURE=false autotest” gives me an endless loop of spec tests…
(I moved your posts to the bottom so we can read them in order. Please
post at the bottom or inline.)
I’ve seen this happen when files are generated during a spec run. What’s
in spec/spec.opts and cucumber.yml?
Not sure what I must have bumped, but autotest won’t run any specs–only features. No errors are given on startup. I’ve taken “export AUTOFEATURE=true” out of my ./bashrc file–now I just get a blank screen when running autotest. Adding “export RSPEC=true” to .bashrc doesn’t change anything either.
(I moved your posts to the bottom so we can read them in order. Please post at the bottom or inline.)
default: <%= std_opts %> features
wip: --tags @wip:3 --wip features
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
Unless you’re running cucumber with --profile rerun, this shouldn’t be a
problem.
Do any of your specs generate files? Also, did you try both “autotest”
and “bundle exec autotest” with the same results?
at.clear_mappings # take out the default (test/test*rb)
end
Gems included by the bundle:
capybara (0.3.9)
mime-types (1.16)
rspec-expectations (2.0.0.beta.20)
This is driving me up the wall…any ideas?
Get rid of ‘Autotest.add_discovery { “rails” }’ from ./autotest/discover.rb.
Add autotest-rails to the Gemfile.
Apologies - this changed and I forgot. Put “Autotest.add_discovery {
“rails” }” back in ./autotest/discover.rb and put autotest (not
autotest-rails) in the Gemfile.
DavidStrange…that does work, but now autotest seems caught in an infinite loop. When I run autospec, the specs run, then the features, then the features again…and again…and again…and so on. If I run autotest as follows: “AUTOFEATURE=false autotest”, I don’t have the problem. Any other ideas?
rerun_opts = rerun.to_s.strip.empty? ? “–format #{ENV[‘CUCUMBER_FORMAT’] || ‘progress’} features” : “–format #{ENV[‘CUCUMBER_FORMAT’] || ‘pretty’} #{rerun}”
std_opts = “–format #{ENV[‘CUCUMBER_FORMAT’] || ‘progress’} --strict --tags ~@wip”
%>
default: <%= std_opts %> features
wip: --tags @wip:3 --wip features
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
Unless you’re running cucumber with --profile rerun, this shouldn’t be a problem.
Do any of your specs generate files? Also, did you try both “autotest” and “bundle exec autotest” with the same results?
Argh…this problem stopped occurring–thought I wouldn’t have to deal
with it again. Same setup as we’ve already discussed–just a loop of
cucumber features. Specs are run, but only once when a file is changed,
and then it’s back to the features loop. I’ve tried both “autotest” and
“bundle exec autotest”. “autotest” gives me the behaviour I’ve
described. “bundle exec autotest” yields the following error:
internal:lib/rubygems/custom_require:29: warning: loading in progress,
circular require considered harmful -
/Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb
from internal:lib/rubygems/custom_require:29:in require' from <internal:lib/rubygems/custom_require>:29:inrequire’
from
/Users/brennon/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0.rc.6/lib/bundler/setup.rb:1:in <top (required)>' from <internal:lib/rubygems/custom_require>:29:inrequire’
from internal:lib/rubygems/custom_require:29:in require' from /Users/brennon/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:2:in<top (required)>’
from internal:lib/rubygems/custom_require:29:in require' from <internal:lib/rubygems/custom_require>:29:inrequire’
from
/Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:1136:in <top (required)>' from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:968:inload_plugins’
from
/Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:968:in each' from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:976:inblock in load_plugins’
from
/Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:976:in load' from /Users/brennon/.rvm/gems/ruby-1.9.2-p0@stan/gems/hanna-0.1.12/lib/rubygems_plugin.rb:2:in<top (required)>’
from internal:lib/rubygems/custom_require:29:in require' from <internal:lib/rubygems/custom_require>:29:inrequire’
from
/Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/doc_manager.rb:8:in <top (required)>' from <internal:lib/rubygems/custom_require>:29:inrequire’
from internal:lib/rubygems/custom_require:29:in `require’
/Users/brennon/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:84:
warning: method redefined; discarding old gem
/Users/brennon/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:81:
warning: previous definition of gem was here
/Users/brennon/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:116:
warning: method redefined; discarding old from_gems_in
/Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/source_index.rb:75:
warning: previous definition of from_gems_in was here
/Users/brennon/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:125:
warning: method redefined; discarding old refresh
/Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:728:
warning: previous definition of refresh was here
/Users/brennon/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:126:
warning: method redefined; discarding old bin_path
/Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:323:
warning: previous definition of bin_path was here
/Users/brennon/.rvm/gems/ruby-1.9.2-p0@stan/gems/autotest-4.3.2/lib/autotest.rb:275:
warning: (…) interpreted as grouped expression
loading autotest/cucumber_rails
Error loading Autotest style autotest/cucumber_rails (no such file to
load – autotest/rails). Aborting.
“export RSPEC=true” to .bashrc doesn’t change anything either.
in an infinite loop. When I run autospec, the specs run,
[‘CUCUMBER_FORMAT’] || ‘pretty’} #{rerun}"
bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:2:in <top rubygems.rb:976:in block in load_plugins’
/Users/brennon/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0.rc.
was here
/Users/brennon/.rvm/gems/ruby-1.9.2-p0@stan/gems/autotest-4.3.2/lib/
autotest.rb:275: warning: (…) interpreted as grouped expression
loading autotest/cucumber_rails
Error loading Autotest style autotest/cucumber_rails (no such file
to load – autotest/rails). Aborting.
Any ideas? Thanks!
Anyone have any ideas? I’m dyin’ without autotest here…
That error is coming from Cucumber. What versions of everything are
you working with?
<%
Do any of your specs generate files? Also, did you try both “autotest” and “bundle exec autotest” with the same results?
from internal:lib/rubygems/custom_require:29:in require' from <internal:lib/rubygems/custom_require>:29:inrequire’
loading autotest/cucumber_rails
Error loading Autotest style autotest/cucumber_rails (no such file to load – autotest/rails). Aborting.
Any ideas? Thanks!
Anyone have any ideas? I’m dyin’ without autotest here…
Get rid of ‘Autotest.add_discovery { “rails” }’ from ./autotest/discover.rb.
I’ve seen this happen when files are generated during a spec run. What’s in spec/spec.opts and cucumber.yml?
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
from /Users/brennon/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0.rc.6/lib/bundler/setup.rb:1:in <top (required)>' from /Users/brennon/.rvm/gems/ruby-1.9.2-p0@stan/gems/hanna-0.1.12/lib/rubygems_plugin.rb:2:in<top (required)>’
/Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:728: warning: previous definition of refresh was here
That error is coming from Cucumber. What versions of everything are you working with?
Hi, Dave–thanks for the response. I’m using:
Not sure what I must have bumped, but autotest won’t run any specs–only features. No errors are given on startup. I’ve taken “export AUTOFEATURE=true” out of my ./bashrc file–now I just get a blank screen when running autotest. Adding “export RSPEC=true” to .bashrc doesn’t change anything either.
(I moved your posts to the bottom so we can read them in order. Please post at the bottom or inline.)
default: <%= std_opts %> features
from internal:lib/rubygems/custom_require:29:in require' from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:976:inblock in load_plugins’
/Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/source_index.rb:75: warning: previous definition of from_gems_in was here
Anyone have any ideas? I’m dyin’ without autotest here…
rspec-core (2.0.0.beta.20)
rspec-expectations (2.0.0.beta.20)
rspec-mocks (2.0.0.beta.20)
rspec-rails (2.0.0.beta.20)
Thanks, again.
Turns out that uninstalling ZenTest, autotest (shouldn’t there be a
conflict between these two?), autotest-rails, autotest-growl,
cucumber-rails, and re-"bundle install"ing fixed the problem. No
cucumber errors on “bundle exec autotest”, and RSpec specs are now
picked up when using either “bundle exec autotest”, or just plain ol’
“autotest”.
On Aug 27, 2010, at 6:47 AM, Brennon B. wrote:
And now (I haven’t touched anything…seriously!), even “AUTOFEATURE=false autotest” gives me an endless loop of spec tests…
std_opts = “–format #{ENV[‘CUCUMBER_FORMAT’] || ‘progress’} --strict --tags ~@wip”
from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:968:in `load_plugins’
/Users/brennon/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:81: warning: previous definition of gem was here
Any ideas? Thanks!
cucumber-rails (0.3.2)
rspec (2.0.0.beta.20)
rspec-core (2.0.0.beta.20)
rspec-expectations (2.0.0.beta.20)
rspec-mocks (2.0.0.beta.20)
rspec-rails (2.0.0.beta.20)
Thanks, again.
Turns out that uninstalling ZenTest, autotest (shouldn’t there be a conflict between these two?), autotest-rails, autotest-growl, cucumber-rails, and re-"bundle install"ing fixed the problem. No cucumber errors on “bundle exec autotest”, and RSpec specs are now picked up when using either “bundle exec autotest”, or just plain ol’ “autotest”.
Well that must be satisfying and frustrating at the same time
Glad you got it working.
Cheers,
David
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.