rspec

How do I mock AWS SDK (v2) with rspec?

时光毁灭记忆、已成空白 提交于 2019-12-21 05:56:49
问题 I have a class which reads/processes messages from an SQS queue using the aws-sdk-rails gem (which is a wrapper on aws-sdk-ruby v2). How do I mock the AWS calls so I can test my code without hitting the external services? communicator.rb : class Communicator def consume_messages sqs_client = Aws::SQS::Client.new # consume messages until the queue is empty loop do r = sqs_client.receive_message({ queue_url: "https://sqs.region.amazonaws.com/xxxxxxxxxxxx/foo", visibility_timeout: 1, max_number

Difference between Unit::Test versus Rspec [closed]

牧云@^-^@ 提交于 2019-12-21 05:51:09
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . I am interested in Test::Unit and Rspec . Could someone explain me what is the main difference between the two - in terms of principles on which they operate. 回答1: Test::Unit is more akin to a classic TDD tool like JUnit. Tests are written as classes (because that's how it

how do I test (rspec) a http request that takes too long?

纵然是瞬间 提交于 2019-12-21 05:15:07
问题 How do I test the behavior if a request takes too long with rspec? I am thinking of using thread to mock this: describe "Test" do it "should timeout if the request takes too long" do lambda { thread1 = Thread.new { #net::http request to google.com } thread2 = Thread.new { sleep(xx seconds) } thread1.join thread2.join }.should raise_error end end I want to make sure that after the request is first made, another thread "kicks in" which in this case is just a sleep for xx seconds. Then I should

Running Capybara without rack produces errors when using url parameters

风流意气都作罢 提交于 2019-12-21 04:57:23
问题 Here's my setup, based on this recommendation: How to get Cucumber/Capybara/Mechanize to work against external non-rails site It works until I add parameters to the URL. Any advice on addressing this issue? require 'rspec' require 'capybara/rspec' require 'capybara/dsl' @test_url = "test" RSpec.configure do |config| config.include Capybara::DSL end Capybara.configure do |config| config.run_server = false config.current_driver = :selenium config.app = "fake app name" config.app_host = "http:/

Rspec request specs and Rails 5

元气小坏坏 提交于 2019-12-21 04:51:12
问题 I'm starting a new project, my first with Rails 5.1.0. I have a pb with my first request spec. describe 'Users', type: :request do it 'are created from external data' do json_string = File.read('path/to/test_data/user_data.json') params = { user: JSON.parse(json_string) } headers = { "CONTENT_TYPE" => "application/json" } expect do post '/api/v1/users', params.to_s, headers end.to change { User.count }.by(1) expect(response.status).to eq 200 end end this spec return the error ArgumentError:

Dockerized selenium browser cannot access Capybara test url

情到浓时终转凉″ 提交于 2019-12-21 04:42:21
问题 I am trying to run Ruby on Rails feature tests on dockerized selenium standalone firefox browser. It seems like I am having issues with networking because the selenium instance can't connect to the url started by Capybara. Here's my sample docker-compose.yml file: ff: image: selenium/standalone-firefox:2.48.2 container_name: firefox-browser web: build: . container_name: my-app volumes: - ".:/home/ubuntu/my-app" command: /bin/bash -l scripts/docker-start-tests.sh ports: - "3000:3000" And I

Is it a bad practice to randomly-generate test data?

纵然是瞬间 提交于 2019-12-21 04:40:50
问题 Since I've started using rspec, I've had a problem with the notion of fixtures. My primary concerns are this: I use testing to reveal surprising behavior. I'm not always clever enough to enumerate every possible edge case for the examples I'm testing. Using hard-coded fixtures seems limiting because it only tests my code with the very specific cases that I've imagined. (Admittedly, my imagination is also limiting with respect to which cases I test.) I use testing to as a form of documentation

RCov with RSpec-2

喜夏-厌秋 提交于 2019-12-21 04:34:35
问题 I'm working with a bit of a bleeding edge rails app. Rails 3, RSpec 2, Rspec-Rails2. It seems as if RSpec2 doesn't include the spec:rcov rake task that RSpec 1 has. (at least it isn't there yet) Has anyone had any luck running rcov with rspec 2, or writing their own rake task to make this work? 回答1: Try passing in options to exclude the gem directory. Or since your running rails use the rails flag: desc "Run all specs with rcov" RSpec::Core::RakeTask.new(:rcov => spec_prereq) do |t| t.rcov =

What's the best way to set custom request headers when using Capybara in RSpec request specs?

大憨熊 提交于 2019-12-21 04:26:18
问题 I'm monkey patching Capybara::Session with a set_headers method that assigns to Capybara::RackTest::Browser's options attribute (which I've changed from an attr_reader to an attr_accessor). The patches: class Capybara::RackTest::Browser attr_accessor :options end class Capybara::Session def set_headers(headers) if driver.browser.respond_to?(:options=) #because we've monkey patched it above options = driver.browser.options if options.nil? || options[:headers].nil? options ||= {} options[

Dependent tests in rspec

微笑、不失礼 提交于 2019-12-21 04:13:25
问题 I write functional tests, and I need to do tests that were being would depend on the passage of previous tests. Let's say I have a button that opens a window in which there is a functional. That is, in order to check this functionality, I need to first check the correct operation of the button (ie, open window or not functional). So, I need to do so that would be if the test failed on a button click, the tests did not run to check the functional window. Writing tests separately - for me is