rspec

Stub Faraday request with Webmock - help needed

北城以北 提交于 2020-06-13 09:25:08
问题 I need help stubbing a request using Faraday gem. I am making this request URL='https://secure.snd.payu.com//pl/standard/user/oauth/authorize'.freeze url_encoded = 'grant_type=client_credentials' \ + "&client_id=#{ENV['client_id'}" \ + "&client_secret=#{ENV['client_secret'}" connection = Faraday.new do |con| con.response :oj, content_type: /\bjson$/ con.adapter Faraday.default_adapter end connection.post(URL, url_encoded) which outputs #<Faraday::Response:0x00000000016ff620 @on_complete

How to write down the rspec to test rescue block.?

你说的曾经没有我的故事 提交于 2020-06-08 08:13:06
问题 I have method like this def className def method_name some code rescue some code and error message end end So, How to write down the rspec to test rescue block..? 回答1: If you want to rescue, it means you expect some code to raise some kind of exception. You can use RSpec stubs to fake the implementation and force an error. Assuming the execution block contains a method that may raise def method_name other_method_that_may_raise rescue => e "ERROR: #{e.message}" end hook the stub to that method

How to write down the rspec to test rescue block.?

心已入冬 提交于 2020-06-08 08:12:18
问题 I have method like this def className def method_name some code rescue some code and error message end end So, How to write down the rspec to test rescue block..? 回答1: If you want to rescue, it means you expect some code to raise some kind of exception. You can use RSpec stubs to fake the implementation and force an error. Assuming the execution block contains a method that may raise def method_name other_method_that_may_raise rescue => e "ERROR: #{e.message}" end hook the stub to that method

Running an RSpec test suite against a TimescaleDB database with Rails 4.2

99封情书 提交于 2020-06-01 05:57:28
问题 I have a Rails 4.2.11.1 application that I am trying to use with a TimescaleDB database. I've solved the majority of the issues already (using the composite_primary_keys gem to get around Timescale's restriction that unique indexes should always include the table's timestamp column). This has my application fully functional, but my test suite fails whenever I try to write to the Timescale table, with the following error: PG::FeatureNotSupported: ERROR: invalid INSERT on the root table of

How to require file from `gem` which are not under `lib` directory?

﹥>﹥吖頭↗ 提交于 2020-05-28 20:05:21
问题 I want to write spec for my rubocop custom cop. This gem has handy helpers defined here. I want to require it. How to achieve what? I've tried to use Gem.find_files , and this gives me ability to require any file in that gem, but only under lib directory. For example: # this requires ...gems/rubocop-0.29.1/lib/rubocop/formatter/formatter_set.rb require Gem.find_files('rubocop/formatter/formatter_set.rb').first # but I need ...gems/rubocop-0.29.1/spec/support/cop_helper.rb The following

Basic browser authentication with Safari Capybara Selenium

陌路散爱 提交于 2020-05-28 07:53:39
问题 I've got a problem with browser authentication on Safari using Capybara/Selenium. I'm using this code to authenticate: visit "https://#{ENV['AUTH_USERNAME']}:#{ENV['AUTH_PASSWORD']}@my-staging-app.heroku.com" This works just fine on Chrome and FF but not on Safari. Any ideas how to bypass this? 回答1: Okey, I've found the solution for this. I had to use reversed proxy using e.g. Nginx and send proper headers :) Here is how I've done it: In this example I'll be using creds login: admin and

Basic browser authentication with Safari Capybara Selenium

巧了我就是萌 提交于 2020-05-28 07:53:21
问题 I've got a problem with browser authentication on Safari using Capybara/Selenium. I'm using this code to authenticate: visit "https://#{ENV['AUTH_USERNAME']}:#{ENV['AUTH_PASSWORD']}@my-staging-app.heroku.com" This works just fine on Chrome and FF but not on Safari. Any ideas how to bypass this? 回答1: Okey, I've found the solution for this. I had to use reversed proxy using e.g. Nginx and send proper headers :) Here is how I've done it: In this example I'll be using creds login: admin and

How can I block external connections with RSpec & Capybara?

僤鯓⒐⒋嵵緔 提交于 2020-05-26 13:40:31
问题 With my Rails project, I would like to write tests non-ideal conditions such as lack of internet connection or timeouts. For example, I am using a gem to contact an API and would like to make sure that I handle the error correctly if there is a connection issue between my app and the external API. I can do this already by making a fixture with VCR and removing the response from the "cassette". However, this has drawbacks: It has to be done manually. The cassettes can not be gitignored if I am

How can I block external connections with RSpec & Capybara?

孤者浪人 提交于 2020-05-26 13:38:48
问题 With my Rails project, I would like to write tests non-ideal conditions such as lack of internet connection or timeouts. For example, I am using a gem to contact an API and would like to make sure that I handle the error correctly if there is a connection issue between my app and the external API. I can do this already by making a fixture with VCR and removing the response from the "cassette". However, this has drawbacks: It has to be done manually. The cassettes can not be gitignored if I am

How to test HTTParty API call with Ruby and RSpec

走远了吗. 提交于 2020-05-23 14:10:29
问题 I am using the HTTParty gem to make a call to the GitHub API to access a list of user's repos. It is a very simple application using Sinatra that displays a user's favourite programming language based on the most common language that appears in their repos. I am a bit stuck on how I can write an RSpec expectation that mocks out the actual API call and instead just checks that json data is being returned. I have a mock .json file but not sure how to use it in my test. Any ideas? github_api.rb