rspec2

FactoryGirl + RSpec + Rails 3 'undefined method <attribute>='

橙三吉。 提交于 2019-12-03 04:53:49
问题 I'm fairly new to rails and TDD (as will no doubt be obvious from my post) and am having a hard time wrapping my brain around Rspec and FactoryGirl. I'm using Rails 3, rspec and factory girl: gem 'rails', '3.0.3' # ... gem 'rspec-rails', '~>2.4.0' gem 'factory_girl_rails' I have a user model that I've been successfully running tests on during development, but then needed to add an attribute to, called "source". It's for determining where the user record originally came from (local vs LDAP).

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

杀马特。学长 韩版系。学妹 提交于 2019-12-03 03:34:06
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 tests, and I have merged old spec_helper.rb and new one(It was generated rails g rspec:install ). ENV[

How to test ApplicationController method defined also as a helper method?

非 Y 不嫁゛ 提交于 2019-12-03 03:29:45
问题 In my ApplicationController I have a method defined as a helper method: helper_method :some_method_here How do I test ApplicationController in RSpec at all? How do I include/call this helper method when testing my views/helpers? I'm using Rails3 with RSpec2 回答1: You can use an anonymous controller to test your ApplicationController, as describe in the RSpec documentation. There's also a section on testing helpers. 回答2: You can invoke your helper methods on subject or @controller in the

How to load a spec_helper.rb automatically in RSpec 2

若如初见. 提交于 2019-12-03 02:57:18
问题 When developing gems in Ruby, I almost always need a file in which I can configure RSpec to my needs and maybe before doing that, require some helper modules which should be available in all my spec examples. In Rails applications a file named spec/spec_helper.rb is used for that. One thing that annoys me is that in the typical Rails environment, you have to require this spec_helper.rb file in every file that contains examples for it to be loaded. In the past I had a lot of problems with this

Rails 3 and Rspec 2 turn off transactional fixtures for individual tests

ぐ巨炮叔叔 提交于 2019-12-03 02:40:02
I am in the process of upgrading my application to Rails 3. I started using Rspec 2 with Rails 3. I need to turn off transactional fixtures for some of my rspec tests. Prior I used the following code in my model specs before(:all) do ActiveSupport::TestCase.use_transactional_fixtures = false end after(:all) do ActiveSupport::TestCase.use_transactional_fixtures = true clean_engine_database end That now gives me the error: Failure/Error: ActiveSupport::TestCase.use_transactional_fixtures = false undefined method `use_transactional_fixtures=' for ActiveSupport::TestCase:Class Is there a way to do

How to ignore or skip a test method using RSpec?

三世轮回 提交于 2019-12-03 01:12:04
please guide how to disable one of the below test methods using RSpec. I am using Selenuim WebDriver + RSpec combinations to run tests. require 'rspec' require 'selenium-webdriver' describe 'Automation System' do before(:each) do ### end after(:each) do @driver.quit end it 'Test01' do #positive test case end it 'Test02' do #negative test case end end You can use pending() or change it to xit or wrap assert in pending block for wait implementation: describe 'Automation System' do # some code here it 'Test01' do pending("is implemented but waiting") end it 'Test02' do # or without message

Stubbing Devise in rSpec and Rails3

ぃ、小莉子 提交于 2019-12-03 01:02:52
问题 How would you stub Devise in Rails 3 with rSpec. I have a UsersController and a User model. Both of which are associated with Devise at the moment, I'm writing controller specs and I really am having a hard time with my expectations as the Devise sign_in is really jamming up the works. Any thing will help. 回答1: I found that it is now pretty easy to do this. There was a problem with rspec2 and devise, but is now solved. I guess you would need to update your gems. Then you can write require

Are there any good mutation testing tools for ruby 1.9 and RSpec2?

*爱你&永不变心* 提交于 2019-12-02 23:00:17
I used to use Heckle, but it is incompatible with ruby 1.9 because of issues with ParseTree. I've looked for alternatives, but the only thing that looked promising was Chaser, and that did not have any clear documentation that I could use to see if I could make it work with RSpec. It seems to have Test::Unit dependencies. So - is anyone out there using any cool tools to really check the quality of your tests? Alternatively - are there any coverage tools that provide better than c0 coverage? This would kind of help solve the same problem. I'm using cover_me at the moment, but it is c0, like

Write controller and feature specs for ActiveAdmin using RSpec?

送分小仙女□ 提交于 2019-12-02 21:16:09
How does one write a controller and feature spec for the following ActiveAdmin code: # app/admin/organization.rb ActiveAdmin.register Organization do batch_action :approve do |selection| Organization.find(selection).each {|organization| organization.approve } redirect_to collection_path, notice: 'Organizations approved.' end end Here is my feature spec. It cannot find 'Batch Actions' which ActiveAdmin loads in the pop-up menu. # spec/features/admin/organization_feature_spec.rb require 'spec_helper' include Devise::TestHelpers describe 'Admin Organization' do before(:each) do @user =

How to test with Rspec if an email is delivered

☆樱花仙子☆ 提交于 2019-12-02 18:50:24
I'd like to test if an email is delivered if I call a controller method with :post. I'll use email_spec so I tried this snipped here: http://rubydoc.info/gems/email_spec/1.2.1/file/README.rdoc#Testing_In_Isolation But it doesn't work, because I pass an instance of the model-object to the delivery-method and the instance is saved before the delivery. I tried to create an other instance of the model-object, but then the id isn't the same. My controller-method looks like this: def create @params = params[:reservation] @reservation = Reservation.new(@params) if @reservation.save ReservationMailer