rspec2

How to get rspec-2 to give the full trace associated with a test failure?

筅森魡賤 提交于 2019-11-27 10:24:16
问题 Right now if I run my test suite using rake spec I get an error: 1) SegmentsController GET 'index' should work Failure/Error: get 'index' undefined method `locale' for # # ./spec/controllers/segments_controller_spec.rb:14: in `block (3 levels) in ' This is normal as I do have an error :) The problem is that the trace isn't very helpful. I know it broke in segments_controller_spec.rb , line 14, but this is just where I call the test: ### segments_controller_spec.rb:14 get 'index' I would

Rspec: expect vs expect with block - what's the difference?

旧街凉风 提交于 2019-11-27 07:48:02
Just learning rspec syntax and I noticed that this code works: context "given a bad list of players" do let(:bad_players) { {} } it "fails to create given a bad player list" do expect{ Team.new("Random", bad_players) }.to raise_error end end But this code doesn't: context "given a bad list of players" do let(:bad_players) { {} } it "fails to create given a bad player list" do expect( Team.new("Random", bad_players) ).to raise_error end end It gives me this error: Team given a bad list of players fails to create given a bad player list Failure/Error: expect( Team.new("Random", bad_players) ).to

ControllerMacros cannot be seen in RSpec

空扰寡人 提交于 2019-11-27 06:48:16
问题 I have a Rails app and I am trying to test it. I use devise to log in. However, I faced a problem that occurs when I want to test: Users/ender/Projects/ratingw/spec/controllers/widgets_controller_spec.rb:4:in `block in <top (required)>': undefined local variable or method `login_user' for #<Class:0x007fe909bd5070> (NameError) First, I want to say that I read this devise formal tutorial. My spec_helper.rb is: # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS

Using implicit `subject` with `expect` in RSpec-2.11

笑着哭i 提交于 2019-11-27 05:32:28
问题 With the new expect syntax in rspec-2.11, how is it possible to use the implicit subject ? Is there a better way than explicitly referencing subject , like below? describe User do it 'is valid' do expect(subject).to be_valid # <<< can `subject` be implicit? end end 回答1: If you configure RSpec to disable the should syntax, you can still use the old one-liner syntax, since that doesn't involve should being added to every object: describe User do it { should be_valid } end We briefly discussed

Turn off transactional fixtures for one spec with RSpec 2

时光毁灭记忆、已成空白 提交于 2019-11-27 05:27:50
问题 How do I turn off transactional fixtures for only one spec (or Steak scenario) with RSpec 2? I tried some things found on the web without any success. This leads to an undefined method exception. describe "MyClass without transactional fixtures" do self.use_transactional_fixtures = false ... end This simply does nothing (transactional fixture is still on): describe "MyClass without transactional fixtures" do RSpec.configure do |config| config.use_transactional_fixtures = false end ... end

Setup RSpec to test a gem (not Rails)

三世轮回 提交于 2019-11-27 04:55:38
问题 It is pretty easy with the added generator of rspec-rails to setup RSpec for testing a Rails application. But how about adding RSpec for testing a gem in development? I am not using jeweler or such tools. I just used Bundler ( bundle gem my_gem ) to setup the structure for the new gem and edit the *.gemspec manually. I also added s.add_development_dependency "rspec", ">= 2.0.0" to gemspec and did a bundle install . Is there some nice tutorial what to do next to get RSpec working? 回答1: I've

Testing STDOUT output in Rspec

a 夏天 提交于 2019-11-27 00:51:39
问题 I am trying to build a spec for this statement. It is easy with 'puts' print "'#{@file}' doesn't exist: Create Empty File (y/n)?" 回答1: RSpec 3.0+ RSpec 3.0 added a new output matcher for this purpose: expect { my_method }.to output("my message").to_stdout expect { my_method }.to output("my error").to_stderr Minitest Minitest also has something called capture_io: out, err = capture_io do my_method end assert_equals "my message", out assert_equals "my error", err RSpec < 3.0 (and others) For

How do I prepare test database(s) for Rails rspec tests without running rake spec?

帅比萌擦擦* 提交于 2019-11-26 19:07:05
问题 After significant troubleshooting, I figured out that I needed to run rake spec once (I can abort with control-c) before I can run rspec directly (e.g. on a subset of our specs). We are running Rails 3.0.7 and RSpec 2.5.0. Clearly, rake is running some important database setup tasks / code (we have custom code in the root level rails Rakefile and possibly other places). How can I run the rake test database setup tasks / code without running rake spec ? In addition to being able to run rspec

rspec 2: detect call to method but still have it perform its function

倖福魔咒の 提交于 2019-11-26 18:32:27
问题 I want to check if a method was called exactly(n) times, but I still want that method to perform its original function. Consider a simple thumbnailing system that caches the thumbnail file and make sure ImageMagick's "convert" executable that creates the thumbnail is only called on the first request. it "this passes: should detect a cached version" do thumbnail_url = thumbnail_url_for("images/something.jpg") get thumbnail_url last_response.should be_ok Sinatra::Thumbnail.should_not_receive(

Rspec: expect vs expect with block - what&#39;s the difference?

旧时模样 提交于 2019-11-26 13:49:19
问题 Just learning rspec syntax and I noticed that this code works: context "given a bad list of players" do let(:bad_players) { {} } it "fails to create given a bad player list" do expect{ Team.new("Random", bad_players) }.to raise_error end end But this code doesn't: context "given a bad list of players" do let(:bad_players) { {} } it "fails to create given a bad player list" do expect( Team.new("Random", bad_players) ).to raise_error end end It gives me this error: Team given a bad list of