rspec2

rspec what is the difference between be nil and be_nil

落花浮王杯 提交于 2020-01-03 07:20:23
问题 I am using rspec and for asserts like student.name should be nil student.name should be_nil Both seem to work. is there a difference between using be nil an be_nil ??? 回答1: There is no difference really, except be nil gets defined on the fly, and be_nil has been specifically programmed by rspec. when you say should.be something , rspec tries the following [:==, :<, :<=, :>=, :>, :===].each do |operator| define_method operator do |operand| BeComparedTo.new(operand, operator) end end Whereas,

rspec returns “PG::Error: ERROR: relation ”table_name“ does not exist”

血红的双手。 提交于 2019-12-31 21:42:34
问题 Environment is REE(2011.12) on rvm, rspec 2.8.0, rails 3.0.6, and pg 0.13.2. Using PostgreSQL 8.3.17 on CentOS 5.6. The db:migrate have work correctly. But rspec have got following error. 1) ApiController articles OK Failure/Error: Unable to find matching line from backtrace ActiveRecord::StatementInvalid: PG::Error: ERROR: relation "table_name" does not exist : DELETE FROM "table_name" I'm updating my project from rails 2.3.5 with rspec 1.x series to rails 3.0 with rspec2. Copied all rspec

Rails 3, RSpec 2.5: Using should_receive or stub_chain with named scopes

隐身守侯 提交于 2019-12-31 10:32:21
问题 I use Rails 3.0.4 and RSpec 2.5. In my controllers I use named scopes heavily, for example @collection = GuestbookEntry.nonreplies.bydate.inclusive.paginate( :page => params[:page], :conditions => { ... }) In my tests, I want to be able to mock the result of such a query, not the wording . I do not think it makes sense to do something like GuestbookEntry.stub_chain(:nonreplies, :bydate, ...).and_return(...) because this test will fail the moment I decide to reorder the named scopes. With

How can I mock super in ruby using rspec?

隐身守侯 提交于 2019-12-30 07:59:08
问题 I am extending an existing library by creating a child class which extends to the library class. In the child class, I was able to test most of functionality in initialize method, but was not able to mock super call. The child class looks like something like below. class Child < SomeLibrary def initialize(arg) validate_arg(arg) do_something super(arg) end def validate_arg(arg) # do the validation end def do_something @setup = true end end How can I write rspec test (with mocha) such that I

What does Steak add beyond just using Capybara and RSpec in Rails testing?

随声附和 提交于 2019-12-30 06:10:30
问题 I'm trying to understand the need for Steak. I get that its like Cucumber, except that you can use pure ruby instead of mapping your english language specs to ruby like in Cucumber, but it says that it mainly adds a wrapper around the RSpec DSL, and lets you use that taken from: http://jeffkreeftmeijer.com/2010/steak-because-cucumber-is-for-vegetarians/ module Spec::Example::ExampleGroupMethods alias scenario example alias background before end module Spec::DSL::Main alias feature describe

“Could not find a valid mapping for #<User …>” only on second and successive tests

…衆ロ難τιáo~ 提交于 2019-12-30 00:53:09
问题 I'm trying to write a request test that asserts that the proper links appear on the application layout depending in whether a user is logged in or out. FWIW, I'm using Devise for the authentication piece. Here's my spec: require 'spec_helper' require 'devise/test_helpers' describe "Layout Links" do context "the home page" do context "session controls" do context "for an authenticated user" do before do # I know these should all operate in isolation, but I # want to make sure the user is

How to test routes in a Rails 3.1 mountable engine

萝らか妹 提交于 2019-12-28 13:42:08
问题 I am trying to write some routing specs for a mountable rails 3.1 engine. I have working model and controller specs, but I cannot figure out how to specify routes. For a sample engine, 'testy', every approach I try ends with the same error: ActionController::RoutingError: No route matches "/testy" I've tried both Rspec and Test::Unit syntax (spec/routing/index_routing_spec.rb): describe "test controller routing" do it "Routs the root to the test controller's index action" do { :get => '/testy

RSpec2 and Capybara

独自空忆成欢 提交于 2019-12-28 13:29:12
问题 Capybara is confusing me. If I use Capybara in combination with Ruby on Rails 3 and RSpec 2, then in RSpec request tests, the following matcher works: response.body.should have_selector "div.some_class" The response object has the class ActionDispatch::TestResponse . But the following line, which should work officially, does not work: page.should have_selector "div.some_class" The page object has the class Capybara::Session . In which cases do you have to use the response.body object and when

Best way to test named scopes in Rails4

风格不统一 提交于 2019-12-25 02:40:58
问题 As a part of the migration from Rails 3.2 to Rails 4, all named scopes need a proc block. Read more here: http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#active-record I had missed updating a scope in one of my models, which ended up biting me in production after my migration. So I wanted to figure out how to test this issue, and I found some strange behavior. In some cases the scopes appear to work fine without the proc, but not in other cases. # models/offer.rb class Offer <

Testing rate-limited external API calls with VCR and RSpec

孤街醉人 提交于 2019-12-24 14:50:12
问题 In my Rails project, I'm using VCR and RSpec to test HTTP interactions against an external REST web service that only allows calls to it once per second . What this means so far is that I end up running my test suite until it fails due to a "number of calls exceeded" error from the web service. At that stage though, at least some cassettes get recorded, so I just continually run the test suite until eventually I get them all recorded and the suite can run using only cassettes (my default