rspec

rspec mock_model model never restored

I'm using rspec 1.3, and using rspec's mock_model to mock out some of the models in my controller tests. I create all the mocks in the before(:each) in the controller spec. I then run my model tests where I build real activerecord objects for setup in before(:each) instead of mocks. It seems that in my model tests, the model is still ...

rspec association test only works in one direction

I upgraded to Rails 3 and RSpec 2 and one of my RSpec tests stopped working: # Job.rb class Job < ActiveRecord::Base has_one :location belongs_to :company validates_associated :location end # Location.rb class Location < ActiveRecord::Base belongs_to :job end # job_spec.rb describe Job, "location" do it "should have a ...

rspec refactoring?

I have the following test, with two almost identical blocks. Now i am looking for ways to refactor this cleanly. The test: context "with the d1 configuration" do before (:each) do # send a message @envelope = Factory(:envelope, :destination => '32495xxxxxx', :message => 'Message sent by d1') @distributor = Distributor.fi...

Testing rails controller with rspec within a plugin

I'm writing a Rails plugin and I'd like to be able to test a controller within the plugin: describe ReportsController, :type => :controller do it "shows paginated reports if the user is authorized" do get 'index' response.should render_template("index") end end unfortunately this results in the following error: NoMethod...

Controller Spec with and without lambda + "should change"

I am testing a simple password reset action and would like RSpec's "change" matcher for lambdas. But it doesn't work for this controller action. Everything works fine without that matcher. Here is the spec: describe "#update" do it "Updates the password and resets the token" do @user = Factory :user getter = lambda{ get :edit,...

creating records in .each in lambda{} doesn't change a number of records in RSpec

I initially wrote testing code like the following; fixtures :records it "should double number of records " do @payment_transactions = PaymentTransaction.find :all length = @payment_transactions.length lambda{ @payment_transactions.each{ |pt| PaymentTransaction.create(:data => pt.data) } }.should change{PaymentTr...

Segmentation Fault in rvm'd Ruby on Mac when running RSpec

I was developing something at the uni, saved to my Dropbox intending to continue at home. This is the message that greeted me: $ spec graph_spec.rb /Users/amadan/.rvm/gems/ruby-1.9.2-rc1/gems/PriorityQueue-0.1.2/ext/priority_queue/CPriorityQueue.bundle: [BUG] Segmentation fault ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10...

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

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 = ...

In rspec, why can't I use be_false etc in helper classes?

When using a helper class with an rspec test, I can't see to use the .should be_false idiom. It's okay in a function defined in a helper .rb file, but when it's within a class the be_false symbol is not found. Example below -- why doesn't this work? How can I use be_false et al in a helper? It seems possible that it's intentional tha...

Disabling Ruby 1.9.x's YARV compiler

There is a very noticeable difference in application initiation time between running my specs from the command line with ruby 1.9.x vs. 1.8.7. My application initiates much faster with ruby 1.8.7 than with ruby 1.9.1 or 1.9.2. The application initiation difference is approximately 18 seconds. It takes about 5 seconds for my app to ini...

Cucumber | Blank page after sending an email

Consider the following example: Scenario: Create New Account (Everything cool) Given I am not authenticated for "wellesley" When I go to register for "wellesley" And I fill in "Name" with "bill" And I fill in "Email" with "[email protected]" And I fill in "Password" with "please" And I fill in "Password Confirmation" with "please" And I ...

Stubbing A Model Attribute

I am writing rspec test for my Cars class, and have a question regarding setting up mocks. I'd like to stub the parts array in Cars, how can i do that? I have the following code: class Cars has_many :parts def heavy_count parts.inject(0) { |sum, v| v.weight > 10 ? sum + 1 : sum } end end With test context ("#heavy_count")...

Render_template error Integration test in Ror

hi, I just trying the integration test in ruby on rails.. I have added a file layout_links_spec.rb require 'spec_helper' describe "LayoutLinks" do it "shuld hve a homepage" do get '/' response.should render_template("pages/home") end it "shuld hve a contactpage" do get '/contact' response.should render...

Testing two different expectations with mocking

I've recently just added Devise to my first Rails3 app, and I'm having a bit of trouble with the controller tests. I'm testing the User controller class, which is the same model that Devise uses. So at the beginning of my spec I have this: before(:each) do sign_in @user = Factory.create(:user) end Now I can get the test passing wit...

Testing Paperclip file uploading with RSpec

I don't really care about testing file uploads, but since I have validates_attachment_presence, etc.. in my model, rspec is complaining. So now I'm creating my model with these attributes in the spec to try and shut it up: @attr = { :name => "value for name", :title => "value for title", :content => "value for content", :pic_fi...

RSpec sees xits but no other tests?

So, whenever I run "rake spec" in my application directory, I see this: admin@nurvus:~/workspace/spec $ rake spec (in /Users/admin/workspace/) DEPRECATION WARNING: Rake tasks in vendor/plugins/abingo/tasks, vendor/plugins/delayed_job/tasks, vendor/plugins/funkytown/tasks, vendor/plugins/funkytown/tasks, vendor/plugins/git_helper/tasks, ...

undefined method `find_link' for #<Cucumber::Rails::World:0x818e02e8> (NoMethodError)

Rspec obviously hates me. I kinda hate him back. #features/step_definitions/custom_steps.rb Then /^I should see the link "([^\"]*)"$/ do |linked_text| find_link(linked_text) end #link.feature Then I should see the link "foo" From terminal: undefined method `find_link' for #<Cucumber::Rails::World:0x818e02e8> (NoMethodError) ./featu...

Create a Ruby RSpec test case for file input

I have a text file which I intend to convert to a CSV (in this case) format. How do I create a proper RSpec test to see if the output will be in the proper format for the following scenario? This is my code: class ProcessLog @@log = Array.new def read_log(log) if File.exists?(log) f = File.open(log, "r") ...

How can I build/create a many-to-many association in factory_girl?

I have a Person model that has a many-to-many relationship with an Email model and I want to create a factory that lets me generate a first and last name for the person (this is already done) and create an email address that is based off of that person's name. Here is what I have for create a person's name: Factory.sequence :first_name ...

Rspec model spec

How do i cover the below method using Rspec? def validate if !self.response.blank? && !self.response.match("<").nil? self.errors.add :base, 'Please ensure that Response field do not contain HTML(< and >) tags' end end Can anybody help? ...