...this instead of the spec_helper: --require rails_helper If you are using parallel_tests and this is not working for you, .rspec might be ignored. Try using a .rspec...

I needed to make sure that an element is visible and not overshadowed by an element that has a higher...

...jQueryUI's Sortable plugin (either directly or via Angular's ui.sortable), you might struggle testing your nice drag&drop GUI since Selenium webdriver does not support native dragging events.

...jQueryUI uses jquery.simulate for their testing, so why shouldn't you? There is even an extension to it that makes testing drag & drop quite easy. Here is what you need...

The ActionDispatch module of Rails gives you the helper method flash to access the flash messages in a response.

...don't provide canditional validations (validations with if: option). Here is how to write tests for the condition: Class: class Employee < ActiveRecored::Base validates :office, presence: true, if: manager?

... end end Test: describe Employee do describe '#office' do context 'is a manager' do before { allow(subject).to receive(:manager?).and_return(true) } it { is_expected.to validate_presence_of(:office...

Plugins (and gems) are typically tested using a complete sample rails application that lives in the spec folder of the plugin. If your gem is supposed to work with multiple...

...by CSS, the following will work with Selenium, but not when using the Rack::Test driver. The Selenium driver correctly only considers text that is actually visible to a user...

...Then I should not see "foobear" This is because the Rack::Test driver does not know if an element is visible, and only looks at the DOM. Spreewald offers steps...

...the print stylesheet. This card describes how to write a simple Cucumber feature that tests some aspects of a print stylesheets. This way, the requirement of having a print stylesheet...

...is manifested in your tests and cannot be inadvertedly removed from the code. Note that you can always use your DevTools to preview the print styles in your browser.

...when it was called during browser interaction in development but doesn't make the test fail. The reason Development autoloading isn't smart enough to find the referenced class

...other environments (test, staging, production) autoloading is disabled, that all classes are already loaded when browser interaction takes place what makes rails able to find the class even without the...

When testing code that uses pushState / replaceState, your browser will appear to navigate away from http://localhost:3000/specs (or wherever you run your Jasmine tests). This is inconvenient, since reloading...

...the document will no longer re-run the test suite. To remedy this, copy the attached file to a place like spec/javascripts/helpers and #= require it from your tests. It will...

makandracards.com

...a problem when using Selenium with Firefox. We recommend using ChromeDriver for your Selenium tests. Firefox will not trigger focus/blur events when its window is not focused. While this makes...

...sense in standard usage, it breaks in parallel test execution. Please do not rely on focus events in your tests. The linked card has an example of how to build...

After installing Bundler 1.1 you will get the following warning when running tests: WARNING: Cucumber-rails required outside of env.rb. The rest of loading is being defered until env.rb is...

To avoid this warning, move 'gem cucumber-rails' under only group :test in your Gemfile The warning is misleading because it has nothing to do with moving cucumber-rails...

docs.ruby-lang.org

...or an argument. return # => LocalJumpError: unexpected return example { return 4 } # => LocalJumpError: unexpected return def test example { return 4 } return 'test' end test # => 4 Note how test returns the return value...

...from the block; neither code after the example invocation (returning "test") nor code after the yield inside example (putsing "done", returning "example") are executed. As you always knew, and in...

You might wonder about this request in your test.log: Started GET "/__identify__" for 127.0.0.1 at 2015-04-29 18:00:02 +0100 This is what happens: For drivers like Selenium...

...last_name = last_name end attr_reader :first_name, :last_name end To just test if an argument is a Person, you have several options: Test that the argument is...

...instance of a certain class expect(object).to receive(:foo).with(instance_of(Person)) Test that the argument responds to certain methods expect(object).to receive(:foo).with(duck_type...

...the user is certain. Solution If you need to circumvent this protection, e.g. to test that your application behaves correctly despite being misused, do this: page.execute_script 'history.back()' page.execute_script...

...already have a database.yml which defines the database for the cucumber environment instead of test. (Spreewald database.sample.yml has changed) Fix Change cucumber to test in your databse.yml test: # <--- adapter: mysql2...

...database: spreewald_test encoding: utf8 host: localhost username: root password: password

If the application under test makes sound, you probably want to disable this during integration testing. You can use the args option to pass parameters to the browser. For Chrome...

...from you Rails timezone settings / system timezone. I usually have this use case in tests. Example Time.parse('2020-08-09 00:00') will return different results e.g...

In Ruby you can communicate between processes with sockets. This might be helpful in tests that validate parallel executions or custom finalization logic after the garbage collector. Here is an...

...headless chrome via Selenium. This might be useful for debugging issues with flaky integration tests or slow page simulations. page.driver.browser.network_conditions = {offline: false, latency: 5, download_throughput: 2 * 1024, upload...

Sometimes PDF cucumber tests fail at the first test run and succeed at the second run. You can fix this with this step: When PDF generation is ready

...current .users container in the DOM: window.reloadUsers = -> $.get('/users').then (html) -> $('.users').html(html) Testing this simple function poses a number of challenges: It only works if there is a...

...The code requests /users and we want to prevent network interaction in our unit test. The AJAX call is asynchronously and we don't have control over when it returns...

...no user at the end of a web browser, e.g. on the console, during tests or during batch processes. You will often want to access Power.current from another model, to...

called as part of processing a browser request, e.g. on the console, during tests and during batch processes. In such cases your model should simply skip authorization and assume...