How to stub an IP in Ruby on Rails, RSpec Version 3 ?
Often when you are writing unit tests, you want to mock your IP address. Some of the uses cases could be – you are checking if IP is within the certain range. For RSpec 2.x mocking IP would look like...
View ArticleHow to mock file upload with RSpec 3.0 ? [SOLVED]
One more note on RSpec 3.0, this time one useful function that mocks File Upload , saves file/archive content to memory so after it you can do whatever your soul wants with it. Test file/archive should...
View ArticleHow to ensure that filename is always unique ? [Ruby]
Hey guys! Happy New Year! I am glad to be back this year with some interesting news. Thank you for blasting my mailbox with your questions and suggestions! I will do my best to answer all of them as...
View ArticleTutorial: How to get data from external API ? PART 1: Getting API Key,...
I have gotten numerous emails with this question. I have decided to build a small app, that is based on the external API. Why do you need to get data from external API ? If you are asking this...
View ArticleTutorial: How to get data from external API ? PART 2: Sending Request,...
Here we are with Part 2 of our tutorial. Who missed the first part – it’s here. Also if you missed it please take a look at the Github Movies-CLI app, which I am taking my examples from. In this part...
View ArticleHow to reverse a String not using built-in reverse method ? How to reverse...
Hello again! I am continuing answering to your questions, this one came from marthab86_. marthab86_ asks: “I know Ruby has .reverse! , but can you show me how to actually reverse a word or a sentence...
View ArticleHow to measure your Ruby method performance ? [Ruby, Benchmark]
Hey Guys, Today, we will use our reverse methods that we have built in the previous post and measure how good they are comparing to the Ruby built in reverse method. For this purpose we will use Ruby...
View Article10 ways how to speed your unit tests [Rails, RSpec, Capybara]
#10 Avoid writing to the database Lets take simple example. I have this test: require 'rails_helper' describe Address do let (:address) {create(:address)} it 'should be valid' do expect(address).to...
View ArticleHow to get stock price from website in terminal
One of our readers asked me how to scrap stock price from the MarketWatch website using Ruby. Many would say – use tools like wget or curl, which makes total sense, and there are many tutorials on...
View ArticleRAILS, HAML : How to put Checkbox and label on the same line, with translations
Hey guys! Today I have decided to share with you little secret, that can save you quite some time, while writing templates with HAML. While creating a form for one of the projects, I needed to put a...
View Article