rspec

Undefined Method in rspec testing

六月ゝ 毕业季﹏ 提交于 2019-12-24 11:52:54
问题 I'm running an integration test in rspec and the test keeps throwing up an undefined method on billed_for : "undefined method billed_for nil:NilClass" require 'user' describe "Integration" do let(:user) { User.new(voucher) } context 'no voucher' do let(:voucher) { nil } it 'should bill default price all the time' do user.bill expect(user.orders[0].billed_for).to eql 6.95 end end end I have a very small user class so far require 'order' require 'voucher' class User attr_accessor :voucher,

Michael Hartl Rails Tutorial (3.2) - Chapter 5 Rspec issue

爱⌒轻易说出口 提交于 2019-12-24 11:32:53
问题 I've completed Chapter 5 and all the exercises. As part of the final exercise, MH has you write tests for the ApplicationHelper method. Once that is done, individual tests pass with: shift-command-T in ST2 (using the sublime-text-2-ruby-tests package) rspec spec/requests/user_pages_spec.rb in the terminal rspec spec/requests/static_pages_spec.rb in the terminal However, if I run all tests with rspec spec/ in the terminal I get this error: /Users/anonymouscoward/rails/railstut/sample_app/spec

find_or_initialize_by in FactoryGirl

那年仲夏 提交于 2019-12-24 11:27:52
问题 I was wondering if there's an equivalent for find_or_initialize_by in FactoryGirl that solve teh following issue: The objective is that the model uses two tables that have the same country. I don't want to use a sequence for the country (as I found for Emails). There's a uniqueness constraint on Country, but my main issue is that it create twice the same record of Country when I call once FactoryGirl.create(:click) Thus, the Validation fail in the test. Rspec: # models/click_spec.rb describe

How to set “programmatically”\“iteratively” each class object attribute to a value?

北战南征 提交于 2019-12-24 11:03:17
问题 I am using Ruby on Rails 3.0.9 and RSpec 2. I am trying to refactoring some spec file in the following way (in order to test with less code similar class object attribute values): [ :attribute_a, :attribute_b, :attribute_c ].each do |attr| before do # HERE I would like to set the "current" 'attr' related to the # class object instance 'attribute_< letter >' (read below for # more information) each time the iterator is called (note: all # following attributes are NOT attr_accesible - for that

How do I 'expect' a chain of methods using Rspec where the first method takes a parameter?

回眸只為那壹抹淺笑 提交于 2019-12-24 10:45:59
问题 I have a method call in a ruby model that looks like the following: Contentful::PartnerCampaign.find_by(vanityUrl: referral_source).load.first Within the models spec.rb file, I'm trying to mock that call and get a value by passing in a param. But I'm having trouble figuring out the correct way of calling it. At the top of my spec.rb file I have: let(:first_double) { double("Contentful::Model", fields {:promotion_type => "Promotion 1"}) } Within the describe block I've tried the following:

ActionController::UrlGenerationError: missing required keys: [:id]

房东的猫 提交于 2019-12-24 10:35:36
问题 I'm running RSpec 3 tests and am getting this same error for this one particular path: Failure/Error: visit book_path ActionController::UrlGenerationError: No route matches {:action=>"show", :controller=>"books"} missing required keys: [:id] My test isn't quite finished, so I'm sure some of the latter code might be incorrect. But I can't get my visit path line to run: ... book = FactoryGirl.build(:book) reviews = FactoryGirl.build_list(:review, 5, book: book) visit book_path reviews.each do

Checking on empty gems cache fails using Serverspec for Docker image build testing

故事扮演 提交于 2019-12-24 10:23:03
问题 I'm currently having an issue with testing Docker image builds by means of Serverspec. In a nutshell, what I want to do is ensuring that during the image build the Ruby gems build cache gets cleared explicitly, e.g. by issuing rm -rf /usr/lib/ruby/gems/*/cache/*.gem in the Dockerfile. The Dockerfile skeleton I'm working with looks like this: # Dockerfile FROM alpine:3.7 RUN apk add --no-cache \ dumb-init \ ruby \ && apk add --no-cache --virtual .build-deps \ build-base \ ruby-dev RUN gem

rails generate rspec:install returns 'Could not find addressable-2.2.8 in any of the sources'

╄→гoц情女王★ 提交于 2019-12-24 09:59:26
问题 Currently I'm going through the Ruby on Rails Tutorial by Michael Hartl, chapter 3 (http://ruby.railstutorial.org/chapters/static-pages#top), and I'm receiving an error after running the following command: rails generate rspec:install This is the error I'm getting: Could not find addressable-2.2.8 in any of the sources Run 'bundle install' to install missing gems. If I rerun 'bundle install', this is what I get for output: Using rake (0.9.2.2) Using i18n (0.6.0) Using multi_json (1.3.5) Using

how to run capybara commands once, then run some tests

吃可爱长大的小学妹 提交于 2019-12-24 08:55:51
问题 I have the given testing code: describe 'A new user', js: true do before do @new_user = Fabricate.build(:user) end it 'should sign up' do #login code visit '/' click_link 'Login' fill_in 'user[email]', :with => @new_user.email fill_in 'user[password]', :with => @new_user.password click_button 'Login now' #login code end page.should have_content("Hello #{@new_user.first_name}!") current_path.should == dashboard_path end it 'should receive a confirmation mail' do #same login code again visit '/

Testing a Rake task that uses OptionParser with RSpec

五迷三道 提交于 2019-12-24 07:29:08
问题 I have a Rake (12.0) task that uses OptionParser to get an argument. The task looks like require 'optparse' namespace :local do task :file do options = Hash.new opts = OptionParser.new opts.on('--file FILE') { |file| options[:file] = file } args = opts.order!(ARGV) {} opts.parse!(args) # Logic goes here. # The following is enough for this question String.new(options[:file]) end end The task can be executed running rake local:file -- --file=/this/is/a/file.ext Now I want to verify with RSpec