rspec

Testing searchkick with RSpec

人走茶凉 提交于 2019-12-20 10:48:25
问题 I would like to create feature specs for searching Patients in my Practice Management app. So far, I have searched the net and have followed suggested solutions from: http://bitsandbit.es/post/11295134047/unit-testing-with-tire-and-elastic-search#disqus_thread and https://github.com/karmi/tire/wiki/Integration-Testing-Rails-Models-with-Tire Both of these articles suggested configurations to spec_helper.rb for ElasticSearch and Tire. Since Searchkick was based on Tire, I applied the solutions

What is the proper way to test 'create' controller actions?

杀马特。学长 韩版系。学妹 提交于 2019-12-20 09:51:12
问题 I am using Ruby on Rails 3.2.2, Rspec 2.9.0 and RspecRails 2.9.0. I would like to test the create controller action but I don't know how to make that the "right"/"proper" way. I "scaffolded" model, controller, view, ... files, so in those files I have the common code generated by Ruby on Rails generators; in my spec file I have: it "assigns @article" do new_article = FactoryGirl.build(:article) Article.should_receive(:new).and_return(new_article) post :create assigns[:article].should eq(new

Rspec stubbing method for only specific arguments

夙愿已清 提交于 2019-12-20 09:46:54
问题 Is there a way to stub method for only specific arguments. Something like this boss.stub(:fire!).with(employee1).and_return(true) If any other employee is passed to boss.fire! method, I'll get boss received unexpected message error, but what I would really like is just to override the method for specific argument, and leave it be for all others. Any ideas how this can be done? 回答1: You can add a default stub for the fire! method which will call original implementation: boss.stub(:fire!).and

Where/how to include helper methods for capybara integration tests

早过忘川 提交于 2019-12-20 09:45:27
问题 I"m using capybara for my integration/acceptance tests. They're in /spec/requests/ folder. Now I have a few helper methods that I use during acceptance tests. One example is register_user which looks like this def register_user(user) visit home_page fill_in 'user_name', :with => user.username fill_in 'password', :with => user.password click_button 'sign_up_button' end I want to use this method in several different acceptance tests (they're in different files). What's the best way to include

Rails/Rspec: Testing delayed_job mails

谁说我不能喝 提交于 2019-12-20 09:35:21
问题 Just wondering how to test that actionmailer requests are actually sent to the delayed_job que in rspec. I would have assumed it was quite simple, but my delayed_job queue doesn't seem to be incrementing. Code below: Controller: def create @contact = Contact.new(params[:contact]) if @contact.save contactmailer = ContactMailer contactmailer.delay.contact_message(@contact) redirect_to(contacts_url) else render :action => "new" end Spec: it "queues mail when a contact is created" do

Should I test private methods using RSpec?

耗尽温柔 提交于 2019-12-20 09:30:02
问题 Is it good practice to write tests for private methods? Consider the following simple example: class Group has_many :members private def release_members members.each { |member| member.update_attributes group_id: nil } end end Would it be good practice to write a test for the release_members method in RSpec? I believe you'd have to write the test calling the method with send ie. group.send(:release_members) which is sometimes frowned upon. 回答1: You can find an in-depth discussion of that very

Rails project using spork - always have to use spork?

笑着哭i 提交于 2019-12-20 09:24:33
问题 If I am using spork in my rails project and have a spec_helper.rb file like this require 'spork' Spork.prefork do ... end Spork.each_run do ... end Does it mean I need to ALWAYS have spork running when I run my specs via rspec spec ? Meaning, if I haven't executed $ spork in a terminal window yet, does it mean my specs will not run properly? 回答1: No. We have spork in our spec helper and we don't use it a lot of the time, since it slows the tests down overall on larger suites. We only run

ActionMailer testing with rspec [closed]

这一生的挚爱 提交于 2019-12-20 09:10:06
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I am developing a Rails 4 application which involves sending / receiving emails. For example, I send emails during user registration, user comment, and other events in the app. I have created all emails using the action mailer , and I used rspec and shoulda for testing. I need to test if the mails are received

Can RSpec stubbed method return different values in sequence?

南楼画角 提交于 2019-12-20 09:09:26
问题 I have a model Family with a method location which merges the location outputs of other objects, Members. (Members are associated with families, but that's not important here.) For example, given member_1 has location == 'San Diego (traveling, returns 15 May)' member_2 has location == 'San Diego' Family.location might return 'San Diego (member_1 traveling, returns 15 May)' The specifics are unimportant. To simplify the testing of Family.location, I want to stub Member.location. However, I

Minitest and Rspec [closed]

删除回忆录丶 提交于 2019-12-20 08:34:09
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I have just watched a Railscast for Minitest. What are the pros and cons for using RSpec vs Minitest for testing a rails app? Which