rspec

Appending headers to Rspec controller tests

◇◆丶佛笑我妖孽 提交于 2020-01-22 09:25:40
问题 I'm trying to write out tests for a controller of mine that takes in requests from external services. So far this is my test: describe ApplyController do context 'when valid' do let(:parameters) do file = File.join File.dirname(__FILE__), '..', 'samples', 'Indeed.json' JSON.parse(File.read file) end let(:signature) { 'GC02UVj0d4bqa5peNFHdPQAZ2BI=' } subject(:response) { post :indeed, parameters, 'X-Indeed-Signature' => signature } it 'returns 200 ok if Request is valid' do expect(response

Ruby + Rspec: How should I be testing attr_accessor?

只谈情不闲聊 提交于 2020-01-22 08:50:27
问题 I have a ReturnItem class. specs: require 'spec_helper' describe ReturnItem do #is this enough? it { should respond_to :chosen } it { should respond_to :chosen= } end class: class ReturnItem attr_accessor :chosen end It seems a bit tedious since attr_accessor is used in practically every class. Is there a shortcut for this in rspec to test the default functionality of a getter and setter? Or do I have to go through the process of testing the getter and setter individually and manually for

Rails - Test validation of enum fields

人走茶凉 提交于 2020-01-21 02:43:13
问题 I'm using Rails 4 enums and I want to properly test them, so I set these tests up for my enum fields: it { should validate_inclusion_of(:category).in_array(%w[sale sale_with_tax fees lease tax_free other payroll]) } it { should validate_inclusion_of(:type).in_array(%w[receivable payable]) } And this is the model they're validating: class Invoice < ActiveRecord::Base belongs_to :user enum category: [:sale, :sale_with_tax, :fees, :lease, :tax_free, :other, :payroll] enum type: [:receivable,

Rails - Test validation of enum fields

人走茶凉 提交于 2020-01-21 02:43:08
问题 I'm using Rails 4 enums and I want to properly test them, so I set these tests up for my enum fields: it { should validate_inclusion_of(:category).in_array(%w[sale sale_with_tax fees lease tax_free other payroll]) } it { should validate_inclusion_of(:type).in_array(%w[receivable payable]) } And this is the model they're validating: class Invoice < ActiveRecord::Base belongs_to :user enum category: [:sale, :sale_with_tax, :fees, :lease, :tax_free, :other, :payroll] enum type: [:receivable,

Rspec incredibly slow after installing Ubuntu 12.04

↘锁芯ラ 提交于 2020-01-20 21:21:26
问题 after installing the newest Ubuntu 12.04 on my machine all the rspec tests for all my rails applications are running very very slow. Also a colleague of mine has the same problem. Anyone an idea what it could be? Its really annoying... 回答1: My specs were taking 4x longer than my coworkers who are running Vagrant on Mac OSX. I found this post which seems to solve the problem. Apparently anyone using ext4 will experience this unless they follow the instructions on the blog post: Open up your

Resetting a singleton instance in Ruby

风流意气都作罢 提交于 2020-01-20 18:30:35
问题 How do I reset a singleton object in Ruby? I know that one'd never want to do this in real code but what about unit tests? Here's what I am trying to do in an RSpec test - describe MySingleton, "#not_initialised" do it "raises an exception" do expect {MySingleton.get_something}.to raise_error(RuntimeError) end end It fails because one of my previous tests initialises the singleton object. I have tried following Ian White's advice from this link which essentially monkey patches Singleton to

Rspec and capybara, difference between visit and get methods, with regards to the current_path object

狂风中的少年 提交于 2020-01-19 04:04:25
问题 I'm possibly confusing rack and capybara methods here let!(:admin){FactoryGirl.create(:admin)} # test passes describe "visiting #edit page" do before { visit edit_user_path(admin) } specify { current_path.should eq(edit_user_path(admin)) } end # test fails describe "getting #edit page" do before { get edit_user_path(admin) } specify { current_path.should eq(edit_user_path(admin)) } end The second test fails with: Failure/Error: specify { current_path.should eq(edit_user_path(admin)) }

rackup (failed to load command)

纵饮孤独 提交于 2020-01-17 08:01:28
问题 When I type: bundle exec rackup it should give some output like this: $ bundle exec rackup [2017-01-29 21:45:56] INFO WEBrick 1.3.1 [2017-01-29 21:45:56] INFO ruby 2.4.0 (2016-12-24) [x86_64-darwin15] [2017-01-29 21:45:56] INFO WEBrick::HTTPServer#start: pid=48002 port=9292 But instead I get this bundler: failed to load command: rackup (/Users/username/.rbenv/versions/2.4.0/bin/rackup) LoadError: cannot load such file -- rails/all « truncated » Here is my gem file: # frozen_string_literal:

RSpec: Cant Verify there are more than 5 Btns on Search Result Page

浪子不回头ぞ 提交于 2020-01-16 18:05:59
问题 I try to do an Selenium-Acceptancetest 'Search Result List' with RSpec spec And my Issue is It should verify the count of a Button "Detail" I would be happy to get help for start thinking as a coder; i am a manual tester stil. My Problem now is: Method Error Failure/Error: expect(@driver.find_element(:xpath, "//a[contains(text(),'Details')]").to be > 4) NoMethodError: undefined method `to' for #<Selenium::WebDriver::Element:0x00000003fd4938> Sources: On my way to resolve the issue I tried to

RSpec: Cant Verify there are more than 5 Btns on Search Result Page

匆匆过客 提交于 2020-01-16 18:05:52
问题 I try to do an Selenium-Acceptancetest 'Search Result List' with RSpec spec And my Issue is It should verify the count of a Button "Detail" I would be happy to get help for start thinking as a coder; i am a manual tester stil. My Problem now is: Method Error Failure/Error: expect(@driver.find_element(:xpath, "//a[contains(text(),'Details')]").to be > 4) NoMethodError: undefined method `to' for #<Selenium::WebDriver::Element:0x00000003fd4938> Sources: On my way to resolve the issue I tried to