Is free and available on many platforms
https://www.virtualbox.org/wiki/Downloads
If you don’t have already a running Windows with IE you can quickly and legally go with this:
http://modern.ie/en-us/virtualization-tools#downloads
If, like me, you need to test against IE9, IE10, IE11 then you’ll need to download 2 VMs, one for each IE version, e.g.:
Once you have your Windows VM up and running, you should ensure java is installed. Install link here:
http://www.java.com/en/download/index.jsp
You may need to retry this download a few times since Windows security scan gives troubles sometimes.
Go to Internet explorer options, follow these screen shots to get all setup:
As of this writing, latest selenium is 2.44.0, search latest at:
http://selenium-release.storage.googleapis.com/index.html
Download these files in you windows VM:
http://selenium-release.storage.googleapis.com/2.44/selenium-server-standalone-2.44.0.jar
http://selenium-release.storage.googleapis.com/2.44/IEDriverServer_Win32_2.44.0.zip
We also need the IE driver, so by using 32 bits version and placing the extracted file into your windows path should get that ready. FYI people had issues with 64 bits versions of the driver so even on an 64 bits Windows machine I suggest you avoid using x64 driver, stick to 32 bits.
If your are unsure where to put the extracted file, copy IEDriverServer.exe
to C:\Windows\System32
Windows protected mode might be enabled, so run manually the file IEDriverServer.exe
, but run it at the location path where you copied it, e.g. C:\Windows\System32
Running that file will trigger the Windows security pop up so you can authorize the executable with Run anyway to get that remembered by Windows:
Then Allow access for it. This is more related to Windows firewall actually:
IMPORTANT Close running IEDriverServer.exe
now, this run was only to trigger Windows security and firewall dialogs.
You can do so by opening the Windows command prompt cmd.exe then type ipconfig
a common port number given by VirtualBox to the VM is 10.0.2.15 and VMWare might look more like 192.168.240.131 but it varies on each environment.
Take note of the IP address and within your host machine edit /etc/hosts file too add a new entry, I use custom domain names ie11.dev and so on like this:
1 2 |
|
So within your Protractor project you will need a config file that points selenium to the proper URL, e.g. a file ie11.conf.js
1 2 3 |
|
Within your Window VM, you should place this ie11.bat
file in the same directory where you downloaded the selenium standalone jar, for example in your downloads folder.
1 2 3 |
|
Note port 4444 is the default selenium port, you can change it if needed. We need Windows firewall to add a rule to allow incoming connections to that port; accept all when the Firewall screen appears after running ie11.bat
IMPORTANT Leave this script running on Windows machine. When you restart the VM you’ll have to manually start ie11.bat
again unless you add it to the startup program list.
We already saw this on step 7 but let’s look again with an alternative syntax:
1 2 3 4 5 6 7 8 |
|
This isn’t the only way to run against IE machine, you could install nodejs there too and install protractor.
Also note, you can go a step further and setup a selenium standalone grid if you want to maintain a more complex infrastructure.
Steps to do that below.
Setting up protractor on Windows is quite doable, download first:
And select Windows Installer of course. I recommend you choose 32 bits installers. Follow setup wizard.
Once installed, open a Command Prompt or CMD.EXE
Install protractor globally:
1
|
|
Make protractor download selenium and IE Driver for you:
1
|
|
You can start selenium on a custom port if need by adding --seleniumPort=4444
1
|
|
Within the host machine, in my case Linux. Instead of running webdriver-manager start
you can switch to a standalone grid, a.k.a “hub” by running this simple command:
1
|
|
Port 6666 is just an arbitrary one, you can stick with 4444 if you like but I prefer to state some difference.
Note you can get selenium standalone jar file with wget:
1
|
|
Also, you may need to open that port 6666 on your firewall, I did it with ufw
in Ubuntu 13:
1
|
|
So leave java -jar selenium-server-standalone
command running in an open terminal, this is the selenium grid that nodes will connect to.
If you want to switch to a selenium grid, you will need to change ie11.bat
file like below. Also note IP 10.0.2.2 is usually VirtualBox host machine IP address, VMWare IP might be 192.168.240.1 when using the NAT interface.
1 2 3 4 5 |
|
Check the selenium grid logs, on your host machine (in my case Linux) to see if the output contains the following error or similar:
1
|
|
That’s the case when the firewall is blocking port 4444 on the guest VM.
If you can not work around it, considering moving your VM network setup from NAT to Bridged. Then you will have to find out the IP address of you host machine, in my case Linux, and replace 10.0.2.2
with that IP, e.g. 192.168.0.3
Networking setup details is are little beyond the scope of this post.
Hope this post helps you.
Have a good time writing e2e protractor tests ! :D
]]>Take a look how this looks like in thor or some tiny gem of mine.
Achieving all that will take some steps, here is how:
For the gem version badge just push to rubygems at least 1 time and the badge will be there for you. Also, the “Version Badge” page offers an easy copy and paste builder of the URL that you can use here
For your build status go to Travis-CI.org and follow the link “Sign in with GitHub”
For gem dependencies status Signup at Gemnasium
For code quality stats Signup at Code Climate
For coverage percentage first Signup once at Coveralls then for each of you projects go to the Add Repo page
For analytics Signup at Google Analytics and Signup at githalytics
For pretty documentation generator read here
or simply go to documentup.com/your_github_user/your_repo_name
Gem version, code climate and gem dependencies do not require more work on your side besides pushing your updates to github, those services will take care of the rest.
Add this .travis.yml
file to your project root, change it depending on the ruby versions you are interested to support:
1 2 3 4 5 |
|
I use SimpleCov for test coverage, coveralls gem take care of your badge,
Add necessary dependencies to your gemspec:
1 2 |
|
If you use rspec, update your spec_helper.rb
and add this lines to the very beginning:
1 2 3 4 5 6 7 8 |
|
Replace strings elgalu with your github user and boolean_class with your github repo name. It’s probably a better idea that you use a templating tool for this like the one I built and use
# TODO: Your gem name
[![Gem Version][GV img]][Gem Version]
[![Build Status][BS img]][Build Status]
[![Dependency Status][DS img]][Dependency Status]
[![Code Climate][CC img]][Code Climate]
[![Coverage Status][CS img]][Coverage Status]
## Description
TODO: Your gem description
[Gem Version]: https://rubygems.org/gems/boolean_class
[Build Status]: https://travis-ci.org/elgalu/boolean_class
[travis pull requests]: https://travis-ci.org/elgalu/boolean_class/pull_requests
[Dependency Status]: https://gemnasium.com/elgalu/boolean_class
[Code Climate]: https://codeclimate.com/github/elgalu/boolean_class
[Coverage Status]: https://coveralls.io/r/elgalu/boolean_class
[GV img]: https://badge.fury.io/rb/boolean_class.png
[BS img]: https://travis-ci.org/elgalu/boolean_class.png
[DS img]: https://gemnasium.com/elgalu/boolean_class.png
[CC img]: https://codeclimate.com/github/elgalu/boolean_class.png
[CS img]: https://coveralls.io/repos/elgalu/boolean_class/badge.png?branch=master
Don’t forget to let me know if i’m missing new cool badges out there!
I’ve recently added githalytics service in order to have Google Analytics for each of my github repos. Note there is also bitdeli service but haven’t tested it yet, let me know if is better or more free.
To do so:
Go to Google Analytics website and signup to get your Property ID, e.g.
Default URL protocol: https://
Default URL source..: github.com/elgalu/time_ago_in_words
You may also delete github.com
from your GA Referral Exclusion List
Go to githalytics and sign up, e.g.
TrackingCode[url]: https://github.com/elgalu/time_ago_in_words
TrackingCode[code]: UA-12345-12
Add the fake image badge that will send data for analytics purposes, e.g.
[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/3fe2425a26ab0ca00b5bc6acf817af59 "githalytics.com")](http://githalytics.com/elgalu/time_ago_in_words)
That should be it. Remember to check later on Google Analytics site for the collected data, works like a charm!
]]>JSONP or “JSON with padding” is a communication technique used in JavaScript. It provides a method to request data from a server in a different domain, something prohibited by typical web browsers because of the same origin policy.
But let’s dig it right away with an example. I will use J50Npi standalone javascript library for that.
Say you want to client-side print the user’s Country IP using some external JSONP free service.
You can test that solution from your browser right now:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
You should see an alert saying your current (ip based location) country name after half a second or so.
]]>You have a couple of options to start your gem files and directory structure, you can choose to write all of if from scratch, copy & paste from another gem source you liked, or use a bootstrap tool that does the work for you.
A popular option is using bundle gem GEMNAME to bootstrap your gem. I started with bundler but right after the third gem i got tired of being fixed to a template not so easy to customize without sticking my nose around bundler source.
So i partially extracted that into a gem called gem-newgem and turned it into a RubyGems plugin which is what i will use in this post.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
If you take a look at the files you will see how your ~/.gitconfig
information is used, the gem name you provided and the summary are used even in the README.md file.
This is how my .gemspec was generated, you’ll soon find out this is opinionated stuff, feel free to modify the template found at ~/.newgem-templates
to get the requirements you need:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
I will just add one runtime dependency there:
1
|
|
By looking at the README.md file, you’ll see how much i like putting badges at the top of the doc. You will need to sign-up to those services to get your gem up and running, i wrote another post on how to do it.
First and foremost, check everything is working with bundler and rspec:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
Everything nice so far!
Now is time to write about what we expect from this gem:
Create a spec file like spec/user_timeline_spec.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Let’s leave out web mocking for now and expect those specs to run against real twitter servers.
Run $ bundle exec rake spec
and watch it fail.
Good luck with that! …. or … take a look at twitter_anonymous_client source code.
Yard is really nice producing beauty documentation files, all you need to do is remember a few keywords:
1 2 3 4 5 6 7 8 9 10 11 |
|
You should always check how your documentation looks like from time to time Run yard server! i will pass a different port cause i’m already using 8808 with something else:
1 2 3 4 5 6 7 8 9 |
|
Open your browser at (http://localhost:8828) and find some of your type errors ;)
Ensure you have your github username configured:
git config --global github.user your_user_name
curl -u your_user_name https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials
### Enter host password for user 'your_user_name': ......
Follow these steps
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
Now tell ma you have your own ruby gem!
If you need to go down into more details you can check:
]]>puts "var value: #{some_var}"
all over your code and even external gems code!
Well i have news for you guys, ruby debug from your terminal is easy.
All you need to start is requiring 'debug'
when calling your ruby script or ruby binary:
ruby -r debug your_program.rb
Below, take a look at how i debugged thor gem to add a new config option:
I executed some thor script with ruby -rdebug script.rb
then:
1 2 3 4 5 6 7 8 9 |
|
Play around in that console as you normally do with irb and..
have fun!!
]]>Normally, you would invoke this thor task newgem from the command-line like this:
$ thor newgem some_name --test-framework rspec
But what if you need to do that from another ruby script?
Well, you can do so by passing the arguments directly, like this:
1 2 |
|
Using start is a way to go, but thor documentation suggest using invoke() instead, like this:
1 2 3 4 |
|
Good look with your ruby scripting!
]]>But to use mixins as a way to reuse code. Car and Aircraf, for example, are both kind of vehicles but a Car may include a Wheeled mechanism while an Aircraft an Air::Skied one:
1 2 3 4 5 6 7 8 9 |
|
Decisions regarding what is what deeply depends on your domain knowledge so you’ll end up with a subjective solution hopefully producing a code nice to read then easy to understand.
]]>