<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>Orlando Del Aguila Blog</title>
 <link href="/feeds/articles.xml" rel="self"/>
 <link href="/"/>
 <updated>2014-04-15T08:35:01-07:00</updated>
 <id>/</id>
 <author>
   <name>PLUG &#8211; Provence Linux User Group</name>
   <email>contact@plugfr.org</email>
 </author>

 
 <entry>
   <title>svbtle-jekyll and kudos_server revamped</title>
   <link href="/code/2013/12/08/svbtle-jekyll-and-kudos-server-revamped.html"/>
   <updated>2013-12-08T00:00:00-08:00</updated>
   <id>/code/2013/12/08/svbtle-jekyll-and-kudos-server-revamped</id>
   <content type="html">&lt;p&gt;I cleaned and extract the code of my blog to its own repo, now you can
install your own instance of &lt;a href=&quot;https://github.com/orlando/svbtle-jekyll&quot;&gt;svbtle-jekyll&lt;/a&gt; and &lt;a href=&quot;https://github.com/orlando/kudos_server&quot;&gt;kudos_server&lt;/a&gt; easily. Just follow the directions in the repo and you should be ready in 5 minutes (now you can deploy &lt;a href=&quot;https://github.com/orlando/kudos_server&quot;&gt;kudos_server&lt;/a&gt; to heroku).&lt;/p&gt;

&lt;p&gt;Also I added a post generator to &lt;a href=&quot;https://github.com/orlando/svbtle-jekyll&quot;&gt;svbtle-jekyll&lt;/a&gt;, and a separate configuration file (inside the &lt;code&gt;_data&lt;/code&gt; folder) to make things cleaner and easier for everyone.&lt;/p&gt;

&lt;p&gt;If you are having problem setting up the blog or just want to fix
something, create an issue or post your pull request.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Shadow DOM 101, Ruby GDL lighting talk.</title>
   <link href="/code/2013/07/12/shadow-dom-101-ruby-gdl-lighting-talk.html"/>
   <updated>2013-07-12T00:00:00-07:00</updated>
   <id>/code/2013/07/12/shadow-dom-101-ruby-gdl-lighting-talk</id>
   <content type="html">&lt;p&gt;i gave a lighting talk yesterday for the ruby gdl user group (&lt;a href=&quot;https://twitter.com/ruby_gdl&quot;&gt;@ruby_gdl&lt;/a&gt;) about Shadow DOM, here are the slides but without notes. The cool thing is that you can look at the resources at the final of the slides, good material in there.&lt;/p&gt;

&lt;div class=&quot;speakerdeck&quot;&gt;
    &lt;script async class=&quot;speakerdeck-embed&quot; data-id=&quot;08028070cd2a013059600aa8ee42777e&quot; data-ratio=&quot;1.3333333333333333&quot; src=&quot;//speakerdeck.com/assets/embed.js&quot;&gt;&lt;/script&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>always, ALWAYS!!, pass your code through JSLint</title>
   <link href="/code/2013/03/17/always-always-pass-your-code-through-jslint.html"/>
   <updated>2013-03-17T00:00:00-07:00</updated>
   <id>/code/2013/03/17/always-always-pass-your-code-through-jslint</id>
   <content type="html">&lt;p&gt;the other day i was coding with JavaScript, everything was good until i deployed my code.. we use jammit for our assets compression, after the compile the files came up empty (0 bytes), that&amp;#39;s a sign that some is wrong (obviously right?)&lt;/p&gt;

&lt;p&gt;well the problem is that when YUI compressor finds an error, then it just stop the whole package compression and says nothing about it (no error message, no file where to check, no nothing..), so i started looking for posible missing &lt;code&gt;;&lt;/code&gt; or stuff like that.&lt;/p&gt;

&lt;p&gt;i found maybe 10 of those missing &lt;code&gt;;&lt;/code&gt;. i fixed them and try to recompile... still not working..&lt;/p&gt;

&lt;p&gt;then some of my friends asked me why i didn&amp;#39;t use &lt;a href=&quot;jslint.com&quot;&gt;JSLint&lt;/a&gt; before all this problem, i realize that they were true, it was a little irresponsible on my part to no validate the coding style using a lint..&lt;/p&gt;

&lt;p&gt;since my editor is &lt;code&gt;vim&lt;/code&gt; then i start looking for a jslint pugling for it (i dont want to be pasting code all the time to JSLint.com), the one i use is &lt;a href=&quot;https://github.com/hallettj/jslint.vim&quot;&gt;jslint.vim&lt;/a&gt; the installation was a breeze, just clone the repo and do a &lt;code&gt;rake install&lt;/code&gt; (off course if you are in OS X, if not then check the repo and follow the instructions there).&lt;/p&gt;

&lt;p&gt;you can set the options for JSLint in &lt;code&gt;~/.jslintrc&lt;/code&gt;, the config file looks something like this&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;text language-text&quot; data-lang=&quot;text&quot;&gt;/*jslint browser: true, regexp: true */
/*global jQuery, $ */

/* vim: set ft=javascript: */
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;there you set all your global variables, libraries etc. also you can set all the options that JSLint has in this file, check &lt;a href=&quot;http://www.jslint.com/lint.html&quot;&gt;http://www.jslint.com/lint.html&lt;/a&gt; for the list of options.&lt;/p&gt;

&lt;p&gt;well after pasing my files through JSLint i found a one error that i totally overlooked.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You shall not use reserved words for object properties (here is a &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Reserved_Words&quot;&gt;list&lt;/a&gt; of JavaScript reserved words).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;actually you can use those, but is not a good practice, also YUI Compressor fails if you use reserved words in your code.. things like &lt;code&gt;foo.class&lt;/code&gt;, &lt;code&gt;foo.delete&lt;/code&gt; &lt;code&gt;var float = 2.2&lt;/code&gt; will fail to compile.&lt;/p&gt;

&lt;p&gt;so i learned a lesson that day, &amp;quot;always, ALWAYS!!, pass your code through JSLint&amp;quot;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Svbtle Jekyll Theme</title>
   <link href="/code/2013/03/10/svbtle-theme-for-jekyll.html"/>
   <updated>2013-03-10T00:00:00-08:00</updated>
   <id>/code/2013/03/10/svbtle-theme-for-jekyll</id>
   <content type="html">&lt;p&gt;The other day browsing around my rss feed, i saw that &lt;a href=&quot;http://twitter.com/steveklabnik&quot;&gt;Steve Klabnik&lt;/a&gt; is using &lt;a href=&quot;https://twitter.com/svbtle&quot;&gt;Svbtle&lt;/a&gt;, i tried to register but is an invitation only magazine, so i didn&amp;#39;t even bother to request an invitation.&lt;/p&gt;

&lt;p&gt;i really like the design, so i cloned it for my Jekyll based page, you can take a look at &lt;a href=&quot;http://github.com/orlando/orlando.github.com&quot;&gt;repo&lt;/a&gt;. All configurations are located at the &lt;code&gt;base.html&lt;/code&gt; file header, you can set all your parameters there.&lt;/p&gt;

&lt;p&gt;The &amp;quot;Kudos&amp;quot; button uses &lt;code&gt;localStorage&lt;/code&gt; to track if the user already &amp;quot;kudoed&amp;quot; a post or not, also you can pass an url parameter so after the user &amp;quot;Kudos&amp;quot; a post, it will send an ajax &lt;code&gt;POST&lt;/code&gt; request with the post id. Those id are grabbed from the post &lt;code&gt;customid&lt;/code&gt; parameter, i need to look for a better way to handle this.&lt;/p&gt;

&lt;p&gt;there&amp;#39;s still a lot missing (like grab the kudo number from an external app) but i will clean the code and add the missing functionality later this week. (off course pull requests are so much welcome &amp;lt;3)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>if rvm takes forever to install</title>
   <link href="/code/2013/02/22/if-rvm-takes-forever-to-install.html"/>
   <updated>2013-02-22T00:00:00-08:00</updated>
   <id>/code/2013/02/22/if-rvm-takes-forever-to-install</id>
   <content type="html">&lt;p&gt;probably you just have to do &lt;code&gt;rvm get stable&lt;/code&gt; and should work ok.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Quickstart with VCR + WebMock + Rspec</title>
   <link href="/code/2012/01/22/quickstart-with-vcr-%2B-webmock.html"/>
   <updated>2012-01-22T00:00:00-08:00</updated>
   <id>/code/2012/01/22/quickstart-with-vcr-+-webmock</id>
   <content type="html">&lt;p&gt;Right now im working in a gem called Rubytrick, its a wrapper for the&lt;a href=&quot;http://www.hattrick.org&quot;&gt;Hattrick&amp;#39;s&lt;/a&gt; CHPP API. Hattrick is a Web soccer simulation game. its pretty fun actually, and can became quickly part of your daily internet life (like Facebook or Twitter).&lt;/p&gt;

&lt;p&gt;since this an API wrapper, its expected to have a lot of HTTP requests, first i was stubbing all this requests by hand using &lt;a href=&quot;https://github.com/bblimke/webmock&quot;&gt;WebMock&lt;/a&gt;, but it was a PITA to write XML data manually just to get my tests pass.. so i start looking for a library that could solve that problem.. and it was &lt;a href=&quot;https://github.com/myronmarston/vcr&quot;&gt;VCR&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;With VCR you make real HTTP requests the first time, then theses requests are saved in a fixture folder, and when a test request the same URL, VCR pass the saved fixture instead of hitting the web once again, its a like magic really, saves a lot of work.&lt;/p&gt;

&lt;p&gt;Well, im using RSpec (unless you are &lt;a href=&quot;http://www.rubyinside.com/dhh-offended-by-rspec-debate-4610.html&quot;&gt;DHH&lt;/a&gt; you should be using it too), so this post will show code that works if you have RSpec too.&lt;/p&gt;

&lt;p&gt;now.. first you install you need to istall &lt;a href=&quot;https://github.com/rspec/rspec&quot;&gt;RSpec&lt;/a&gt; or &lt;a href=&quot;https://github.com/rspec/rspec-rails&quot;&gt;RSpec-rails&lt;/a&gt; if you are using Rails.&lt;/p&gt;

&lt;p&gt;RSpec 2.8 has a command for starting with the default spec skeleton, its really helpful in case youre writing a gem, just install RSpec and then write&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt; 
rspec --init
&lt;span class=&quot;c&quot;&gt;#or&lt;/span&gt;
rspec --init --autotest &lt;span class=&quot;c&quot;&gt;#if your using autotest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;these two commands generate some files to start with RSpec. for now you are done with RSpec, now lets install &lt;a href=&quot;https://github.com/bblimke/webmock&quot;&gt;WebMock&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;the install its easy too just write &lt;strong&gt;gem install webmock&lt;/strong&gt; or write it in your Gemfile and then &lt;strong&gt;bundle install&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;once you have WebMock installed, go to your spec directory and open your spec_helper.rb file.&lt;/p&gt;

&lt;p&gt;add &lt;strong&gt;require &amp;#39;webmock/rspec&amp;#39;&lt;/strong&gt; on top of the file, and thats all for now. by default, WebMock doesnt allow real http connections, so all external requests have to be stubbed, this is easy since when your code makes a request, WebMock gives you a &lt;strong&gt;WebMock::NetConnectNotAllowedError&lt;/strong&gt; with information on how you can stub that request, but since we will be using VCR we dont need to stub anything by ourselfs.&lt;/p&gt;

&lt;p&gt;now we need to install &lt;a href=&quot;https://github.com/myronmarston/vcr&quot;&gt;VCR&lt;/a&gt;. just like WebMock, make a &lt;strong&gt;gem install vcr&lt;/strong&gt; of put it in your Gemfile then &lt;strong&gt;bundle install&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;now that you have VCR installed, we need to configure it. go to your spec_helper.rb file and add this block&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;vcr&amp;#39;&lt;/span&gt;

&lt;span class=&quot;no&quot;&gt;VCR&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cassette_library_dir&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;spec/fixtures/vcr_cassettes&amp;#39;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# where VCR should place the stub files.&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stub_with&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:webmock&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#this tells WebMock to use VCR.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;you have to add &lt;strong&gt;config.extend VCR::RSpec::Macros&lt;/strong&gt; to your RSpec config block to enable VCR&amp;#39;s helpers for RSpec. like this.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;no&quot;&gt;RSpec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;configure&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#other lines&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;extend&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;VCR&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;RSpec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Macros&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;that line enables &lt;strong&gt;use_vcr_cassette&lt;/strong&gt; method for RSpec, you can get more info about this method in the VCR&amp;#39;s &lt;a href=&quot;https://www.relishapp.com/myronmarston/vcr/v/1-3-2/docs/test-frameworks/usage-with-rspec&quot;&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;and now we are ready to start recording requests. im going to paste a spec to explain the work flow.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;spec_helper&amp;#39;&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;describe&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Rubytrick&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;HT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Fans&amp;#39;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;use_vcr_cassette&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:record&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:new_episodes&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;before&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;no&quot;&gt;Rubytrick&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oauth_keys&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:consumer_key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;key&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:consumer_secret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;secret&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt; 
  
  &lt;span class=&quot;n&quot;&gt;before&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:each&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;vi&quot;&gt;@session&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Rubytrick&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;token&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;secret&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;it&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;should have a pull data method&amp;#39;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;vi&quot;&gt;@session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fans&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;respond_to?&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:pull_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;be_true&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;it&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;should retrieve data from hattrick already parsed&amp;#39;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;vi&quot;&gt;@session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fans&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;should_not&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;nil&lt;/span&gt;
    &lt;span class=&quot;vi&quot;&gt;@session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fans&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Hash&lt;/span&gt;
    &lt;span class=&quot;vi&quot;&gt;@session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fans&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:file_name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;fans.xml&amp;#39;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;the important part of this file is the command &lt;strong&gt;use_vcr_cassette&lt;/strong&gt;, the &lt;strong&gt;:record =&amp;gt; :new_episodes&lt;/strong&gt; tells VCR to record new requests, and replay the requests that are already saved. you can ignore the other lines of the spec since these are project specific.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;use_vcr_cassette&lt;/strong&gt; also accepts a name, like &lt;strong&gt;use_vcr_cassette &amp;#39;fixture_name_here&amp;#39;&lt;/strong&gt;, if we dont supply a name, then VCR will create one using the describe header of the spec. in this case, the file that VCR creates its called &lt;strong&gt;Rubytrick_HT_Fans.yml&lt;/strong&gt; and that file contains the entire HTTP response, including header and everything, pretty cool.&lt;/p&gt;

&lt;p&gt;the first time you run your tests, it will take a few seconds to capture the request and save it into the fixture file, but after that, they run really fast.&lt;/p&gt;

&lt;p&gt;and thats all for now, VCR + WebMock makes an awesome couple if you want to test with real data. &lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Some useful tricks</title>
   <link href="/code/2011/12/31/some-useful-tricks.html"/>
   <updated>2011-12-31T00:00:00-08:00</updated>
   <id>/code/2011/12/31/some-useful-tricks</id>
   <content type="html">&lt;p&gt;Today i was looking for a easy way to push to multiple git repos.. a quick look at &lt;a href=&quot;http://stackoverflow.com/a/3195446/536984&quot;&gt;stackoverflow&lt;/a&gt; answered my question.&lt;/p&gt;

&lt;p&gt;once you create your &lt;code&gt;local&lt;/code&gt; git repo, add some remotes.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt; 
git remote add hashlabs git@git.hashlabs.com:orlandodelaguila.github.com.git
git remote add origin git@github.com:orlandodelaguila/orlandodelaguila.github.com.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;then open your .git/config file and look at it.. should look like this one.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;core&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;repositoryformatversion&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; 0
    &lt;span class=&quot;nv&quot;&gt;filemode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;bare&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;logallrefupdates&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;remote &lt;span class=&quot;s2&quot;&gt;&amp;quot;origin&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;url&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; git@github.com:orlandodelaguila/orlandodelaguila.github.com.git
    &lt;span class=&quot;nv&quot;&gt;fetch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; +refs/heads/*:refs/remotes/origin/*
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;remote &lt;span class=&quot;s2&quot;&gt;&amp;quot;hashlabs&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;url&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; git@git.hashlabs.com:orlandodelaguila.github.com.git
  &lt;span class=&quot;nv&quot;&gt;fetch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; +refs/heads/*:refs/remotes/hashlabs/*
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;fire up vim and add another remote that includes multiple urls.. like this&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;remote &lt;span class=&quot;s2&quot;&gt;&amp;quot;all&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;url&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; git@git.hashlabs.com:orlandodelaguila.github.com.git
    &lt;span class=&quot;nv&quot;&gt;url&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; git@github.com:orlandodelaguila/orlandodelaguila.github.com.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;when you do &lt;strong&gt;git push all master&lt;/strong&gt; it would push to the both url in the same order that you write them, one repo at a time. this tricky comes really handy because im lazy and i dont want to type &lt;strong&gt;git push&lt;/strong&gt; multiple times.&lt;/p&gt;

&lt;p&gt;another timesaver trick is using &lt;strong&gt;echo&lt;/strong&gt; for creating .rvmrc and README files.. &lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;c&quot;&gt;#for .rvmrc files&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#if you use --create use will create the gemset if it&amp;#39;s not present&lt;/span&gt;

&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;rvm --create use 1.9.3@orlandodelaguila&amp;quot;&lt;/span&gt; &amp;gt;&amp;gt; .rvmrc

&lt;span class=&quot;c&quot;&gt;#for README.md&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#adding -e enables the interpretation of backslash&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#so you could write an entire readme in 1 line =P.&lt;/span&gt;

&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; -e &lt;span class=&quot;s2&quot;&gt;&amp;quot;#README\n Some text here about your readme &amp;quot;&lt;/span&gt; &amp;gt;&amp;gt; README.md
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;both of these commands will create a new file with the text that you pass with &lt;strong&gt;echo&lt;/strong&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Simple oauth testing with Rspec and Capybara</title>
   <link href="/code/2011/12/18/simple-oauth-testing-with-rspec-and-capybara.html"/>
   <updated>2011-12-18T00:00:00-08:00</updated>
   <id>/code/2011/12/18/simple-oauth-testing-with-rspec-and-capybara</id>
   <content type="html">&lt;p&gt;Today i was looking into Capybara DSL as a replacement to Cucumber, dont get me wrong, i love Cucumber but i want to try something new..&lt;/p&gt;

&lt;p&gt;Using &lt;a href=&quot;https://github.com/intridea/omniauth&quot;&gt;OmniAuth&lt;/a&gt; + &lt;a href=&quot;https://github.com/arunagw/omniauth-twitter&quot;&gt;OmniAuth-Twitter&lt;/a&gt; makes oauth with twitter painless. The setup its pretty straight forward, just put this 2 in your Gemfile, bundle install and follow the instructions in the OmniAuth github page, you could check the &lt;a href=&quot;https://github.com/railsapps/rails3-mongoid-omniauth/wiki/Tutorial&quot;&gt;RailsApps tutorial&lt;/a&gt; if you have any doubt.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/rspec/rspec-rails&quot;&gt;Rspec&lt;/a&gt; and &lt;a href=&quot;https://github.com/jnicklas/capybara&quot;&gt;Capybara&lt;/a&gt; install its a breeze too, just follow the steps in the github page and you will get it running in just a few minutes.&lt;/p&gt;

&lt;p&gt;now that you have Rspec and Capybara installed, were ready to start with the code. 
  at this point you should have in your config/routes.rb something like this.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt; 
&lt;span class=&quot;n&quot;&gt;match&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/auth/:provider/callback&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;sessions#create&amp;#39;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;That line will tell OmniAuth what controller should receive the data from twitter (in short.. the callback).
With that line in place, we could use the helpers that OmniAuth has for testing.. go to your spec/spec_helper.rb file and add this.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  
&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;
&lt;span class=&quot;no&quot;&gt;RSpec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;configure&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;OmniAuth&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;test_mode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;true&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;OmniAuth&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mock_auth&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:twitter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;s1&quot;&gt;&amp;#39;provider&amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;twitter&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;s1&quot;&gt;&amp;#39;uid&amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;123545&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;that tells RSpec that when a test hits &amp;#39;auth/twitter&amp;#39; OmniAuth will respond with a mockup, this comes really handy because you dont have to use something like FakeWeb to fake the http responses and its a lot easier using the OmniAuth&amp;#39;s Build in methods.&lt;/p&gt;

&lt;p&gt;Since i have some validations in my User model, i have to pass more data in the mock.. so my mock looks something like this&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;
&lt;span class=&quot;no&quot;&gt;RSpec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;configure&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;OmniAuth&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;test_mode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;true&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;OmniAuth&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mock_auth&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:twitter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;s1&quot;&gt;&amp;#39;provider&amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;twitter&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;s1&quot;&gt;&amp;#39;uid&amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;123545&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;s1&quot;&gt;&amp;#39;info&amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Orlando&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;nickname&amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;djlandox&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;my SessionsController and my User model looks something like this&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SessionsController&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ApplicationController&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;new&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;redirect_to&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/auth/twitter&amp;#39;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;create&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;auth&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;env&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;omniauth.auth&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;auth&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:user_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;redirect_to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;root_url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:notice&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Bienvenido! &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;titleize&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;failure&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;redirect_to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;root_url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:alert&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Error en el Login&amp;#39;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;destroy&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;reset_session&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;redirect_to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;root_url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:notice&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Vuelve Pronto!&amp;#39;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  
&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;User&lt;/span&gt;
  &lt;span class=&quot;kp&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Mongoid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Document&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:provider&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;String&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:uid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;String&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;String&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:email&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;String&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:screen_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;String&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:image_url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;String&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:user_role&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;String&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;validates_presence_of&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:uid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:provider&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;create_with_omniauth&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;auth&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;create!&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;provider&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;auth&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;provider&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;uid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;auth&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;uid&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;auth&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;info&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;auth&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;info&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;email&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;auth&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;info&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;email&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;screen_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;auth&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;info&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;nickname&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;image_url&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;auth&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;info&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;image&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;with all the code in place, the following tests should be green :), create a folder in your spec directory and a file called something like oauth_spec.rb&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;rspec&amp;#39;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;capybara/rspec&amp;#39;&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;feature&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;OmniAuth&amp;quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;scenario&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;should login successfully&amp;quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;visit&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/auth/twitter&amp;#39;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;page&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;have_content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Bienvenido! Orlando&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;scenario&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;should logout successfully&amp;quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;visit&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/auth/twitter&amp;#39;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;page&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;have_content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Bienvenido! Orlando&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;click_on&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Log out&amp;#39;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;page&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;have_content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Vuelve Pronto!&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;when you hit visit &amp;#39;/auth/twitter&amp;#39;, OmniAuth will respond with a POST call to the SessionsController#create method, and that methods redirect to root_url&amp;#39; with a flash message..&lt;/p&gt;

&lt;p&gt;and thats how you easily test OmniAuth with Capybara and RSpec. :)&lt;/p&gt;
</content>
 </entry>
 

</feed>
