rspec3

In RSpec, using let variable inside before :all block

荒凉一梦 提交于 2019-12-01 02:09:23
I have the following code inside most of my tests: describe 'index' let(:company) { FactoryGirl.create(:company) } let(:user) { FactoryGirl.create(:user, company: company) } before do sign_in user visit products_path end ... end But I'm getting the following warning: WARNING: let declaration 'user' accessed in a 'before(:all)' My question is, what is the correct way of doing this? I can't find much information about the warning itself. Thanks! EDIT: My goal is to use the user variable so I can pass it on to sign_in, which signs the user in, and use it later on another tests (I check for the

What is the difference between “be_true” and “be true” in RSpec

半腔热情 提交于 2019-11-30 11:34:23
Can any one please explain me about the difference between be_true and be true in Ruby with simple example. I have also seen be_true and be_false are changed to be_truthy and be_falsey I have an example where 'be true' worked, but when I tried to use 'be_true' or 'be_truthy' spec failed. I am using RSpec version 3.1.7 According to this thread be_true and be_false are now known as be_truthy and be_falsy . The basic difference between be true and be_truthy or be false and be_falsy is that be_falsy / be_truthy matcher passes if the "expected result"(i.e. any object) is (for be_falsy )/ is not

rspec 3 - stub a class method

∥☆過路亽.° 提交于 2019-11-30 11:11:10
问题 I am upgrading from rspec 2.99 to rspec 3.0.3 and have converted instance methods to use allow_any_instance_of , but haven't figured out how to stub a class method. I have code like this: module MyMod class Utils def self.find_x(myarg) # Stuff end end end and my rspec 2 test does this: MyMod::Utils.stub(:find_x).and_return({something: 'testing'}) What is the Rspec 3 way of doing this? 回答1: You should do allow(MyMod::Utils).to receive(:find_x).and_return({something: 'testing'}) Check out the

rspec 3 - stub a class method

大憨熊 提交于 2019-11-30 00:12:38
I am upgrading from rspec 2.99 to rspec 3.0.3 and have converted instance methods to use allow_any_instance_of , but haven't figured out how to stub a class method. I have code like this: module MyMod class Utils def self.find_x(myarg) # Stuff end end end and my rspec 2 test does this: MyMod::Utils.stub(:find_x).and_return({something: 'testing'}) What is the Rspec 3 way of doing this? You should do allow(MyMod::Utils).to receive(:find_x).and_return({something: 'testing'}) Check out the doco Method stubs . 来源: https://stackoverflow.com/questions/25066699/rspec-3-stub-a-class-method

RSpec allow/expect vs just expect/and_return

天涯浪子 提交于 2019-11-29 20:08:26
In RSpec, specifically version >= 3, is there any difference between: Using allow to set up message expectations with parameters that return test doubles, and then using expect to make an assertion on the returned test doubles Just using expect to set up the expectation with parameters and return the test double or is it all just semantics? I know that providing/specifying a return value with expect was the syntax in RSpec mocks 2.13 , but as far as I can see, the syntax changed in RSpec mocks 3 to use allow . However, in the (passing) sample code below, using either allow / expect or just

What is the difference between “be_true” and “be true” in RSpec

风流意气都作罢 提交于 2019-11-29 17:16:34
问题 Can any one please explain me about the difference between be_true and be true in Ruby with simple example. I have also seen be_true and be_false are changed to be_truthy and be_falsey I have an example where 'be true' worked, but when I tried to use 'be_true' or 'be_truthy' spec failed. I am using RSpec version 3.1.7 回答1: According to this thread be_true and be_false are now known as be_truthy and be_falsy . The basic difference between be true and be_truthy or be false and be_falsy is that

RSpec allow/expect vs just expect/and_return

ぃ、小莉子 提交于 2019-11-28 15:09:11
问题 In RSpec, specifically version >= 3, is there any difference between: Using allow to set up message expectations with parameters that return test doubles, and then using expect to make an assertion on the returned test doubles Just using expect to set up the expectation with parameters and return the test double or is it all just semantics? I know that providing/specifying a return value with expect was the syntax in RSpec mocks 2.13, but as far as I can see, the syntax changed in RSpec mocks

Rspec email_spec issue

吃可爱长大的小学妹 提交于 2019-11-28 11:15:25
问题 I am going through this User Authentication tutorial.. http://larsgebhardt.de/user-authentication-with-ruby-on-rails-rspec-and-capybara/ ..which uses the gem 'email_spec'. Granted the author is using an earlier version of rails and rspec, I am having issues getting the gem to work properly. When adding.. spec_helper.rb RSpec.configure do |config| ... config.include(EmailSpec::Helpers) config.include(EmailSpec::Matchers) ... end I receive the error.. Neither Pony nor ActionMailer appear to be

rspec failing error: expected false to respond to `false?`

匆匆过客 提交于 2019-11-28 08:57:35
I am running this portion of a test: describe Dictionary do before do @d = Dictionary.new end it 'can check whether a given keyword exists' do @d.include?('fish').should be_false end With this code: class Dictionary def initialize @hash = {} end def add(new_entry) new_entry.class == String ? @hash[new_entry] = nil : new_entry.each { |noun, definition| @hash[noun] = definition} end def entries @hash end def keywords @hash.keys end def include?(word) if @hash.has_key?(word) true else false end end end I don't know what I'm doing wrong, but my tests keep failing and saying this: > 1) Dictionary

expected true to respond to true?

大憨熊 提交于 2019-11-28 07:08:47
I upgraded my rspec-rails to 3.0.1 and now I'm seeing this error on all of my tests Failure/Error: Sidekiq::Status::complete?(json.jid).should be_true expected true to respond to `true?` I can't find the solution nor what I'm missing. From rspec 3.0, be_true is renamed to be_truthy and be_false to be_falsey The behavior has not changed. So (nil).should be_falsey (false).should be_falsey will pass, and (anything other than nil or false).should be_truthy will also pass From the changelog 3.0.0.beta1 / 2013-11-07 Rename be_true and be_false to be_truthy and be_falsey. (Sam Phippen) To not to