In my latest project, I am rewriting a PHP script that checks the SERPs of a website in various search engines. In the original PHP script there were several lines of code that weren't needed. There also are problems with how the script "pulls" links from Google... it's not really a problem, per se, but a strange way to go about it.
In adapting this code to Ruby, I decided to start out by just having it check Google SERPs, so the original PHP script has been edited in order to make my job of rewriting the script in Ruby a lot easier.
I intend, from this point, to use RSpec to better test and develop the script as I'm already finding a number of bugs that are making the development process a headache. I find that if I write tests, I can check whether or not the code is working without opening my browser and entering different examples that could break the code. Doing it manually is not only time-consuming, but it also makes it difficult to remember what conditions I've tested and which I haven't.
In this script, the user may enter several keywords and their website url in order to check where their website places in the SERPs for each keyword. At this point, I am working to make a clean list/array of keywords... removing any extraneous commas, spaces, newlines, and returns. A sample "clean" array would look like the following:
array = ['code gurl', 'RSpec', 'tennis', 'Sinatra', 'Flying Spaghetti Monster']
In hand-testing (without RSpec) the code, I've come up with some problems/specs to keep in mind:
Cannot separate list by a space as the user is not required to use a space to denote a new keyword. Note: If a user enters multiple words on a single line without comma separation, they will be counted as a single keyword to account for longtail keywords. I think that covers everything.
The tests aren't written, but I do think that currently, the code would pass. However, if I had the tests written, I would haven't to wonder/worry if any changes to the code would break something. Currently in order to check that, I would have to manually enter the keywords (as pictured above) for each case and visually check out the results to see if it passes all cases. With testing it would just say "Hey, you passed this one, this one, and failed this one." Handy!
View the code here
Stay updated and follow the SERP checker project here