What does Integration testing mean ? Wiki says: Integration testing is the phase in software testing in which individual software modules are combined and tested as a group [Read More] When a software grows(may it be written in Ruby or Java or any other language for that matter), stability can become an issue as the application evolve and grow. Integration tests provide a great way to perform end-to-end tests that validate the application is performing as expected. The BDD-TDD life cycle goes as follows: Integration relates more towards BDD, so let's briefly get to know how BDD works. When
When to mock and How to mock
What is mock ? A mock is an object which we can use on behalf of another object. In short, mocking is creating (fake) objects that simulate the behavior of Real Objects. An object under test may have dependencies on other (complex) objects. To isolate the behavior of the object you want to test you replace the other objects by mocks that simulate the behavior of the real objects. When to mock ? Mocking is required when real objects are impractical to incorporate into the unit test. Most of the time external services or methods we have to mock. Once mocked, the
Why and How to write specs?
Why write tests ? Some answers might be Because I have been told by my manager Some could be yay! let's bolt on writing tests because it's cool But some meaningful reasons could be Test-Driven Development is a developer practice that involves writing tests before writing the code being tested. Begin by writing a very small test for code that does not yet exist. Run the test, and, naturally, it fails. Now write just enough code to make that test pass. No more. It gives a strong base for your project or library or even a framework to build upon flawlessly
Fragment caching and sweeping strategy
Rails provides three types of caching techniques: page caching action caching fragment caching The rails_guides_on_caching is the best place to know how it works. This article is to demonstrate fragment caching the Rails Way with various data-stores and clearing those cached fragments on ActiveRecord callbacks on CRUD operations. Rails ActiveSupport::Cache::Store is responsible to do all the read and write operations. 1. The setup By default caching is disabled in rails. You will find the following config commented out in production.rb # Use a different cache store in production # config.cache_store = :mem_cache_store You
Example usage of Redis - LUA script in Rails
This topic is about using Redis and LUA script in Rails. Before proceeding, you may like to read [ Introduction to LUA script with Redis] Redis doesn't have any command to calculate total number of keys We'll use [zrangebyscore] to find number of members between index range. Instal [redis-rb] Start rails console Prepare a dataset based on timestamp > t10 = 10.minutes.ago => 1386935151 > t20 = 20.minutes.ago => 1386934568 > t30 = 30.minutes.ago => 1386933971 > t40 = 40.minutes.ago => 1386933374 This is non-realistic data, may vary for you. Populate redis with Sorted Set > redis = Redis.new # initialize redis => # zadd -
Introduction to LUA script with Redis
What is Redis ? We all might be familiar with [Redis] . For those who are not - It's a "NoSQL" key-value data store. More precisely, it is a data structure server. To read more - [Redis-Wiki] Do [try redis] it has a nice interactive tutorial. To install and setup redis on your machine see [how-to-install-and-use-redis] What is LUA ? LUA is an embeddable scripting language. About LUA - http://www.lua.org/about.html Redis >= 2.6 supports embedded scripting language. Lets give a try to it. To run a script in redis we need
Hub - create a new github repo!
hub is a command line tool that wraps git in order to extend it with extra features and commands that make working with GitHub easier. Install $ gem install hub $ hub hub standalone > ~/bin/hub && chmod +x ~/bin/hub check successful installation with $hub version Create a new github repo demo-project$ git create [NAME] [-p] [-d DESCRIPTION] [-h HOMEPAGE] annotations -p create a private repository -d set the repository's description -h set the homepage URL This will create a new public GitHub repository from the current git repository and add remote origin at "email@example.com:USER/REPOSITORY.git"
Capybara-Webkit : How it works and its anomolies
Crawling and Scraping Techniques in Ruby
Problem case to solve : Crawl any given site(url), scrape each page uniquely for content from given selector or Xpath Available options for Crawling and Scraping : With [libxml2] [Nokogiri] is one of the fastest HTML/XML parser. Almost all of the scraping tools written in Ruby such as Mechanize, Wombat, Anemone, etc. uses Nokogiri as there base DSL for sraping. [Mechanize] - Is a beast in this category. It efficiently uses Nokogiri for HTML scrapping. Do see Abi's post on [Automating browser navigation's through Script] [Wombat] takes the scraping term to a next higher level,
Faster Specs with FixtureBuilder
What is [fixture_builder] ? Fixture Builder creates fixtures based on your definitions of [FactoryGirl] Why fixture_builder ? In projects with huge test suite, its possible that the creation of AR objects hinders the test performance. So to gain performance, we can avoid the redundant database transaction by building subsequent fixtures. Examples https://github.com/rdy/fixture_builder#example It gives tremendous boost to your test execution time. For us the statistics for 550 test cases were : Before fixture_builder ~ 2.5 hours After fixture_builder ~ 19.37 minutes Note : This should be backed up by proper [DatabaseCleaner]