rspec-rails

Why after_commit not running even with use_transactional_fixtures = false

喜夏-厌秋 提交于 2019-12-05 12:05:57
问题 Transactional fixtures in rspec prevent after_commit from being called, but even when I disable them with RSpec.configure do |config| config.use_transactional_fixtures = false end The after_commit callback does not run. Here is a rails app with the latest rspec / rails that I have produced the issue on: git://github.com/sheabarton/after_commit_demo.git 回答1: One way around this is to trigger the commit callbacks manually. Example: describe SomeModel do subject { ... } context 'after_commit' do

Capybara choose(“radio button”) not working

邮差的信 提交于 2019-12-05 12:05:30
A snapshot of my view: <%= form_for @request do |f| %> <div class="form-group"> <%= f.radio_button(:item, "Snow/waterproof shell (upper)") %> <%= f.label(:item, "Snow/waterproof shell (upper)") %> </br> <%= f.radio_button(:item, "Headlamp") %> <%= f.label(:item, "Headlamp") %> </div> Yet on my Rspec integration test file (spec/requests/requests_spec.rb), when I write (note the choose radio button is a part of the form where the user requests an item from a list, and the test is for the resulting page after submission, which should indicate the item that the user requested). I'm using gem

How can I specify https protocol in routing spec with rspec?

守給你的承諾、 提交于 2019-12-05 08:07:37
In my routes file I have: resources :subscription, :only => [:show], :constraints => {:protocol => "https"} I'm trying to add a spec for this route like this: it "recognizes and generates #show" do { :get => "/subscription", :protocol => 'https' }.should route_to(:controller => "subscriptions", :action => "show") end However, the spec still fails. If I remove the :protocol => 'https' , the spec also fails: ActionController::RoutingError: No route matches "/subscription" The (undocumented?) solution is to simply include an entire dummy url, like so: it "recognizes and generates #show" do { :get

Rspec rendering text

心已入冬 提交于 2019-12-05 03:44:05
I have this Code if @temp_user.save sign_in(:user, @temp_user) render text: "OK" else render text: render_to_string(:partial => "errors") end and I try verify with rspec the render "OK" this is my actual spec: it "render text OK" do post :create, {:agent => valid_attributes} # response.should have_content("OK") response.should render_template(:text => "OK") end but this spec respond 0 failures always, even when I put "OKI" in place "OK" anyone have one suggestion for that? If you are using rails 3 or above expect(response.body).to eq "OK" will work response.body.should == "OK" works for me

Rspec extremely slow

依然范特西╮ 提交于 2019-12-05 02:23:25
问题 My rspec tests seem to run extremely slow even with guard & spork. Finished in 5.36 seconds 13 examples, 2 failures I understand that there are several things I can do to optimize my tests & reduce interaction with the database, but I strongly suspect that the spec_helper has been improperly setup. I'm on rails 3.2.11 with mongoid. Database cleaner cleans up after every run. spec_helper.rb require 'rubygems' require 'spork' Spork.prefork do ENV["RAILS_ENV"] ||= 'test' require File.expand_path

Rails rspec and omniauth (integration testing)

余生颓废 提交于 2019-12-05 02:01:49
My Rails 3.2 app uses OmniAuth and Devise to sign in with Twitter. The authentication system works fine. I would like to write an integration test in rspec to make sure everything works. Using the information in the wiki, I've written the following, but I know I'm missing things. Under test.rb in config/environments, I have the following lines OmniAuth.config.test_mode = true OmniAuth.config.mock_auth[:twitter] = {:provider => 'twitter', :uid => '123545'} My rspec test looks like this: describe "Authentications" do context "without signing into app" do it "twitter sign in button should lead to

Rspec rails printing lot of warnings

梦想的初衷 提交于 2019-12-05 01:55:56
I am testing a rails 4.1.0 application with rspec-rails 3.0.1. rspec command is printing a large number of warnings about the gems I am using in the application. I have included a part of the output below. I want to know whether is it possible to suppress this. /home/indika/Documents/rails/news_app/config/initializers/kramdown.rb:6: warning: method redefined; discarding old convert_img /home/indika/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/kramdown-1.4.0/lib/kramdown/converter/html.rb:259: warning: previous definition of convert_img was here /home/indika/.rbenv/versions/2.1.1/lib/ruby

I can't seem to add “config.include FactoryGirl::Syntax::Methods” to my rspec config block in spec_helper.rb

一笑奈何 提交于 2019-12-05 01:38:27
If I add: config.include FactoryGirl::Syntax::Methods under RSpec.configure do |config| and run rspec, I see this error: /Users/perry_mac/rails_projects/mymri/spec/spec_helper.rb:21:in `block in ': uninitialized constant FactoryGirl (NameError) my gemfile.lock can be seen in this pastebin my gemfile can be seen in this pastebin If I omit the Rspec.comfigure statment, my tests all run fine. I'd like to make use of the abbreviated syntax, but am not sure what I am doing wrong here. You must add this string in file 'spec/ RAILS _helper.rb' not in 'spec_helper.rb' Got it. This link showed me the

method stubbing on before(:all)

泪湿孤枕 提交于 2019-12-05 01:13:47
require './spec/spec_helper' require './bank' describe Bank do context "#transfer" do before(:all) do @customer1 = Customer.new(500) customer2 = Customer.new(0) @customer1.stub(:my_money).and_return(1000) customer2.stub(:my_money).and_return(0) @transfer_message = Bank.new.transfer(@customer1, customer2, 2000) end it "should return insufficient balance if transferred amount is greater than balance" do expect(@transfer_message).to eq("Insufficient funds") end it "calls my_money" do expect(@customer1).to have_received(:my_money) end end end When I use before(:each) instead before(:all) it works.

Testing controllers with Minitest

[亡魂溺海] 提交于 2019-12-05 00:26:44
I'm trying to find examples of testing controllers with Minitest, but I've only found a couple and the just verify what template is rendered and that 'success' is returned. That doesn't seem very helpful to me. Is Minitest used to test controllers? The Railscast ( http://railscasts.com/episodes/327-minitest-with-rails ) and a couple other posts I've found seem to do model tests with Minitest and integration tests with Capybara. What about controller tests? Can they be tested with Minitest? If so, are there any real-world examples that actually test the actions? It seems very odd that I can't