rspec

Rails Model Testing - Mocking vs. Factories

安稳与你 提交于 2019-12-21 17:33:11
问题 What's the best practice for Rails testing for mocking objects vs. using factory objects. Should mocking only be used when a model might go to an external source? Or do you only use factories when you're testing the actual model and using mocking for everything else. For example if we have a sales system with customers and orders when we test the customer models do we mock the order or do we just use a factory order? Does it even make a difference? 回答1: We've had this debate often at our web

testing threaded code in ruby

☆樱花仙子☆ 提交于 2019-12-21 17:29:45
问题 I'm writing a delayed_job clone for DataMapper. I've got what I think is working and tested code except for the thread in the worker process. I looked to delayed_job for how to test this but there are now tests for that portion of the code. Below is the code I need to test. ideas? (I'm using rspec BTW) def start say "*** Starting job worker #{@name}" t = Thread.new do loop do delay = Update.work_off(self) #this method well tested break if $exit sleep delay break if $exit end clear_locks end

Getting nokogiri to use a newer version of libxml2

丶灬走出姿态 提交于 2019-12-21 13:35:32
问题 I've been trying to get Nokogiri installed on my computer (Mountain Lion) to use with rspec and capybara, but for the life of me, I can't get it to run properly. From what I can tell, the issue is with nokogiri using the wrong version of libxml2. I've so far tried uninstalling and reinstalling libxml2 using Homebrew (making sure it's the most recent one), uninstalling and reinstalling nokogiri using bundle, and specifying the exact path to the libxml2 files that Homebrew installed when

What testing frameworks are used for Rails? [closed]

女生的网名这么多〃 提交于 2019-12-21 12:35:41
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . What unit testing frameworks are used for Rails? I am reading the book (Pragmatic Programmers Agile Dev. with Rails) which shows how to do unit tests in Rails. The book showed me the default rails testing suite (a subclass of Test::Unit ). Is this the main testing framework

call a specific url with rspec

瘦欲@ 提交于 2019-12-21 12:27:39
问题 I want to create a get request in rspec. get :exec, {:query=>"bla", :id => "something", :user_id => "user" } This builds a URL like: /user/query/something/exec?query=bla The thing is that my controller checks the request it gets and the url must look like: /user/query/something/_XXX_/exec?query=bla How can I do something like this in rspec? (The XXX is hard-coded in the routes.rb file.) 回答1: I'm assuming you're referring to a controller spec. When you pass in a hash like in your example, the

undefined method `rspec_reset' with rspec version 2.14

别说谁变了你拦得住时间么 提交于 2019-12-21 12:07:04
问题 I am trying execute test cases with rspec version 2.14 for which I am getting following error undefined method `rspec_reset' for I am trying to use rspec_reset on the class. The same test cases are working with rspec 2.13.1. So is it possible that rspec_reset method is not available after 2.13? 回答1: Yes, in 2.14, rspec_reset is no longer available on all objects as it was previously, as discussed in https://github.com/rspec/rspec-mocks/pull/250. Although I can't find any documentation on it,

Access to request object in request specs

谁说我不能喝 提交于 2019-12-21 09:03:15
问题 How can I set the request headers before doing the request on a request spec? I'm moving controller specs to request specs on my API using Rails. One thing I'm stuck on is that I have no access to a request object to allow the requests. On my controller specs, I have access to a method I created which signs a specific user: def sign_in(user) token = user.api_keys.first.token # note the request object being used in the next line request.env["HTTP_AUTHORIZATION"] = ActionController:

Setting Content-Type header for RSpec and Rails-API

坚强是说给别人听的谎言 提交于 2019-12-21 08:56:04
问题 I'm using the rails-api gem to build a web service and want to test my API with RSpec. Every request I make, regardless of the HTTP method has the CONTENT_TYPE header set as "application/x-www-form-urlencoded". This isn't really a problem until I try to use wrap_parameters in my controller and it's not have any affect on the params hash: class ApplicationController < ActionController::API include ActionController::ParamsWrapper end class ProjectsController < ApplicationController wrap

How to call a rake task in rspec

巧了我就是萌 提交于 2019-12-21 08:45:51
问题 I am trying to invoke a rake task in in my rspec. require "rake" rake = Rake::Application.new Rake.application = rake rake.init rake.load_rakefile rake['rake my:task'].invoke But i am getting error Failure/Error: rake['rake db:migrate'].invoke RuntimeError: Don't know how to build task 'rake db:migrate' Does anyone have a idea how we can invoke rake task in rspec code. Any help would be highly appreciated. 回答1: To pass in the arguments in square brackets to invoke : rake sim:manual_review

How to call a rake task in rspec

99封情书 提交于 2019-12-21 08:45:10
问题 I am trying to invoke a rake task in in my rspec. require "rake" rake = Rake::Application.new Rake.application = rake rake.init rake.load_rakefile rake['rake my:task'].invoke But i am getting error Failure/Error: rake['rake db:migrate'].invoke RuntimeError: Don't know how to build task 'rake db:migrate' Does anyone have a idea how we can invoke rake task in rspec code. Any help would be highly appreciated. 回答1: To pass in the arguments in square brackets to invoke : rake sim:manual_review