rspec

How to assert that a method call was not made, without any_instance?

ε祈祈猫儿з 提交于 2020-01-15 01:22:25
问题 I have a class, that in one situation should call :my_method , but in another situation must not call method :my_method . I would like to test both cases. Also, I would like the test to document the cases when :my_method should not be called. Using any_instance is generally discouraged, so I would be happy to learn a nice way to replace it. This code snippet is a reduced example on what I kind of test I would like to write. class TestSubject def call call_me end def call_me; end def never

How to auto-load data in the test database before to test my application?

删除回忆录丶 提交于 2020-01-14 22:48:51
问题 I am using Ruby on Rails 3.0.9 and RSpec 2. I would like to auto-load seed data in the test database before I tesst my application. That is, at the testing start up time (when I run tests) I would like to "auto-populate"\"auto-boot" the test database . How can I populate the database with seed data? P.S. : As I read around, (maybe) I should populate the test database by adding some code to the /spec/spec_helper.rb file... but what code and how? In my task/custom.rake file I have: namespace

Using RSpec to test user input with gets

会有一股神秘感。 提交于 2020-01-14 10:32:32
问题 I'm new to Unit Testing using RSpec and Ruby and I have a question on how to test if my code is using the gets method, but without prompting for user input. Here is the code I'm trying to test. Nothing crazy here, just a simple one liner. my_file.rb My_name = gets Here's my spec. require 'stringio' def capture_name $stdin.gets.chomp end describe 'capture_name' do before do $stdin = StringIO.new("John Doe\n") end after do $stdin = STDIN end it "should be 'John Doe'" do expect(capture_name).to

Using RSpec to test user input with gets

吃可爱长大的小学妹 提交于 2020-01-14 10:31:28
问题 I'm new to Unit Testing using RSpec and Ruby and I have a question on how to test if my code is using the gets method, but without prompting for user input. Here is the code I'm trying to test. Nothing crazy here, just a simple one liner. my_file.rb My_name = gets Here's my spec. require 'stringio' def capture_name $stdin.gets.chomp end describe 'capture_name' do before do $stdin = StringIO.new("John Doe\n") end after do $stdin = STDIN end it "should be 'John Doe'" do expect(capture_name).to

Create users in Factory Girl with OmniAuth?

空扰寡人 提交于 2020-01-14 10:16:17
问题 I am currently creating an application that uses OmniAuth to create and authenticate users. I am encountering problems during testing due to Factory Girl being unable to generate users without OmniAuth. I have several different ways to get factory girl to create users with omniauth but none have been successful. I have added the following 2 lines to my spec_helper file OmniAuth.config.test_mode = true \\ allows me to fake signins OmniAuth.config.add_mock(:twitter, { :uid => '12345', :info =>

rspec Bisect Runs Indefinitely

独自空忆成欢 提交于 2020-01-14 10:15:50
问题 I'm seeing some unexpected behavior regarding rspec --bisect when running on circleci. Often times the bisect runs indefinitely until it times out after 5 hours. Bisecting appears to be working initially, but once it reaches the expected end, it begins to slowly examine subsets in the opposite direction until it times out. My Env: Ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16] RSpec 3.7 - rspec-core 3.7.1 - rspec-expectations 3.7.0 - rspec-mocks 3.7.0 - rspec-rails 3.7.2 - rspec

Create users in Factory Girl with OmniAuth?

自作多情 提交于 2020-01-14 10:14:30
问题 I am currently creating an application that uses OmniAuth to create and authenticate users. I am encountering problems during testing due to Factory Girl being unable to generate users without OmniAuth. I have several different ways to get factory girl to create users with omniauth but none have been successful. I have added the following 2 lines to my spec_helper file OmniAuth.config.test_mode = true \\ allows me to fake signins OmniAuth.config.add_mock(:twitter, { :uid => '12345', :info =>

Create users in Factory Girl with OmniAuth?

时间秒杀一切 提交于 2020-01-14 10:14:11
问题 I am currently creating an application that uses OmniAuth to create and authenticate users. I am encountering problems during testing due to Factory Girl being unable to generate users without OmniAuth. I have several different ways to get factory girl to create users with omniauth but none have been successful. I have added the following 2 lines to my spec_helper file OmniAuth.config.test_mode = true \\ allows me to fake signins OmniAuth.config.add_mock(:twitter, { :uid => '12345', :info =>

Capybara::ElementNotFound: Unable to find xpath “/html”

谁说胖子不能爱 提交于 2020-01-14 10:13:08
问题 I'm following the Ruby on Rails tutorial at http://ruby.railstutorial.org/chapters/static-pages and came across the following error StaticPages Home page should have the content 'Sample App' Failure/Error: page.should have_content('Sample App') Capybara::ElementNotFound: Unable to find xpath "/html" # (eval):2:in `text' # ./spec/requests/static_pages_spec.rb:7:in `(root)' My Gem file is as follows source 'http://rubygems.org' gem 'rails', '3.0.10' gem 'jruby-openssl' gem 'activerecord

Rails/rspec: how to set cookies in a request spec?

时间秒杀一切 提交于 2020-01-14 07:18:48
问题 How do I set cookies in my request specs? The solutions on the following page did not work: Rspec: setting cookies in a helper test Namely, request.cookies[:whatever] = 'something' says that request is a nil object. I also tried helper.cookies[:whatever] = 'something' , and that also did not work ( helper in that case was nil ). 回答1: Try just the following: cookies[:whatever] = 'something' 回答2: Make sure you are using the rspec-rails gem and are requiring 'rspec/rails' in your spec_helper,