rspec

Adding rspec test for library module doesn't seem to pickup Expectations and Matchers

流过昼夜 提交于 2019-12-21 03:49:30
问题 I'm adding more rspec testing to my app and would like to test a ScoringMethods module, which is in /lib/scoring_methods.rb. So I added a /spec/lib directory and added scoring_methods_spec.rb there. I required spec_helper and set up the describe block as so: require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe ScoringMethods do describe "should have scorePublicContest method" do methods = ScoringMethods.instance_methods methods[0].should match(/scorePublicContest/)

What's the best way to test delayed_job chains with rSpec?

£可爱£侵袭症+ 提交于 2019-12-21 03:45:14
问题 Currently when I have a delayed method in my code like the following: CommentMailer.delay.deliver_comments(@comment, true) I write something like this in my spec: dj = mock("DelayProxy") CommentMailer.should_receive(:delay).and_return(dj) dj.should_receive(:deliver_comments).with(comment, true) Is there a better way to handle this and/or chained methods like that in rSpec in general? 回答1: We can just have one more line in the before block as following: CommentMailer.stub(:delay).and_return

Ruby Debug “no such file to load --spec_helper”

馋奶兔 提交于 2019-12-21 03:31:18
问题 Noob who may be missing something obvious ... I'm trying to debug an Rspec file. The Rspec file is stripped down at this point: require 'spec_helper' describe PagesController do render_views describe "GET 'home'" do describe "when not signed in" do before(:each) do get :home end it "should be successful" do response.should be_success end it "should have a vendor section" do response.should have_selector("h1", :content => "Vendor") end it "should have a hospital section" do response.should

Filtering sensitive data with VCR

倾然丶 夕夏残阳落幕 提交于 2019-12-21 03:29:10
问题 I'm using VCR gem to record http interactions and replay them in future. I want to filter-out my actual password value in the uri request. Here's sample of what the uri looks like: http://services.somesite.com/Services.asmx/Cabins Username=long&Password=john&StartDate=03%2F22%2F2012&EndDate=03%2F29%2F2012 Though an explanation is provided here, I'm still not sure how to do it after a few attempts myself: https://www.relishapp.com/myronmarston/vcr/v/2-0-0/docs/configuration/filter-sensitive

stub method only on the first call with Rspec

感情迁移 提交于 2019-12-21 03:19:41
问题 How can I stub a method only on the first call, and in the second one it should behave as expected? I have the following method: def method do_stuff rescue => MyException sleep rand retry end I want to the first call of do_stuff to raise MyException , but in the second call, behaves normally. I need to achieve this to test my rescue block without getting an infinite loop. Is there a way to achieve this? 回答1: You can pass a block to a stub that will be invoked when the stub is called. You can

RSpec: how to stub inherited method current_user (w/o Devise)?

廉价感情. 提交于 2019-12-21 03:13:34
问题 I have a controller based on MHartl's RoR4 Tutorial And just like MHartl, I'm not using Devise , I rolled my own authentication system Having trouble with the RSpec for UsersController#Edit since the view has a call to current_user.admin? and the controller calls @path_switch = path_switch I keep getting RSpec errors along the lines of: 1) User Pages Edit Failure/Error: visit edit_user_path(user) NoMethodError: undefined method `admin?' for nil:NilClass # ./app/controllers/users_controller.rb

Trying to use rspec, but getting an error that rspec-core 2.2.1 has been activated, but my Gemfile requires rspec-core 2.1.0

爷,独闯天下 提交于 2019-12-20 19:34:45
问题 I've update my gems. I've created a sample Rails app and have the following in my Gemfile: source 'http://rubygems.org' gem 'rails', '3.0.3' gem 'sqlite3-ruby', :require => 'sqlite3' group :development do gem 'rspec-rails' end group :test do gem 'rspec' gem 'webrat', '0.7.1' end However, when I run 'rspec spec/', I get the following message: /home/jeff/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.7/lib/bundler/runtime.rb:27:in `block in setup': You have already activated rspec-core 2.2.1, but

DHH on Unit Testing : Is RSpec indeed needlessly complicated?

给你一囗甜甜゛ 提交于 2019-12-20 19:25:07
问题 I happen to be a subscriber of Ruby Inside, since I'm particularly interested in Rails. Yesterday, the creator of Rails, David Heinemeier Hansson, pretty much said that he's just using test/unit. I would understand that, since it's Rails internal, but he seems to have given a strong opinion. He believes that RSpec and Cucumber are needlessly complicated. I would normally not pay much attention, but it depends on who says something. I respect Hansson a lot and his opinion got me thinking. When

How can I get Rspec to run all tests nested under a folder?

筅森魡賤 提交于 2019-12-20 17:38:14
问题 I like to run my Rspec tests with Spork running in a separate tab. I usually run my tests using rspec spec , by which I intend to say "search recursively and run everything in the spec folder." I've recently realized that this does not actually run all my tests. I now have a spec file in spec/requests which isn't being run. I know this because I've edited one of the tests to raise an error, and run the following: rspec spec - no error raised. rspec spec/requests - still no error raised, and 0

factory_girl + rspec doesn't seem to roll back changes after each example

戏子无情 提交于 2019-12-20 17:34:23
问题 Similar to the problem described here: http://rpheath.com/posts/411-how-to-use-factory-girl-with-rspec in Short (shorten'd code): spec_helper: config.use_transactional_fixtures = true config.use_instantiated_fixtures = false factories.rb: Factory.define :state do f.name "NY" end in my spec before(:each) do @static_model = Factory(:state) # with validate uniqueness of state name end error: duplicate entry name "NY" etc. Question: Shouldn't rspec clear database before each spec example and