tag:blogger.com,1999:blog-21459744924121888822024-02-08T11:23:41.519-08:00Data. Code. Scotch.You Stay ClassyUnknownnoreply@blogger.comBlogger12125tag:blogger.com,1999:blog-2145974492412188882.post-10681647194816994822012-12-14T15:04:00.002-08:002012-12-14T15:08:41.573-08:00man: can't set the locale; make sure $LC_* and $LANG are correctSometimes a new Ubuntu image will pop-up messages like:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">man: can't set the locale; make sure $LC_* and $LANG are correct</span><br />
<br />
It doesn't stop anything from working, it just gets annoying. It seems to be an release problem, and can be quickly fixed by adding an LC_ALL and LANG definition to <span style="font-family: Courier New, Courier, monospace;">/etc/environment</span> like this:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><span style="background-color: white; color: #333333; font-size: 13px; line-height: 20.799999237060547px;">LC_ALL=</span></span><span style="color: #333333; font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="line-height: 20.799999237060547px;">en_US.UTF-8</span></span><br />
<span style="font-family: Courier New, Courier, monospace;"><span style="background-color: white; color: #333333; font-size: 13px; line-height: 20.799999237060547px;">LANG=</span></span><span style="color: #333333; font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="line-height: 20.799999237060547px;">en_US.UTF-8</span></span><br />
<br />
Other valid values is "<span style="background-color: #fcfdfe; color: #333333; line-height: 19px;"><span style="font-family: Courier New, Courier, monospace;">en_GB.UTF-8</span></span>" and "<span style="font-family: Courier New, Courier, monospace;">en_AU.UTF-8</span>".<br />
<br />
After adding those lines, I had to regenerate the locales with:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">$ sudo locale-gen en_US</span><br />
<span style="font-family: Courier New, Courier, monospace;">$ sudo locale-gen en_US.UTF-8</span><br />
<br />
Check out <a href="https://help.ubuntu.com/community/EnvironmentVariables" target="_blank">Ubuntu's Environment Variables</a> if you want to know more.Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-2145974492412188882.post-10441645959562922072011-12-13T09:24:00.000-08:002011-12-16T10:39:16.084-08:00Sexy Charts FTW in Rails (+ making a Shopify App)I was applying for a job at <a href="http://shopify.com/" target="_blank">Shopify</a> and decided that the best way to woo them was with <b>Sexy Charts</b>™.<br />
<br />
<span class="Apple-style-span" style="font-size: large;">Charting Options for Rails</span><br />
I think the <b>sexiest Sexy Charts</b>™ out there right now are <a href="http://www.highcharts.com/" target="_blank">Highcharts</a>, but their commercial pricing is <a href="http://www.highcharts.com/products/highcharts" target="_blank">a bit steep</a>. As part of the application process I was making a <a href="http://apps.shopify.com/" target="_blank">Shopify App</a>, and while the aim isn't to sell it on the store in the short-term, you never know right? Because of this I didn't want to use Highcharts, and risk incurring their <b>Licensing Wrath</b>. The next-best option was <a href="http://code.google.com/apis/chart/" target="_blank">Google Chart API</a>, which I had wanted to try for a while. I was pleasantly surprised to find out they had gotten a whole lot sexier than the last time I looked at them (check out the home page for examples, and make sure you mouse-over the graphs).<br />
<br />
<span class="Apple-style-span" style="font-size: large;">Building a Shopify App</span><br />
If you're in to Rails like I'm in to Rails, a great place to start is the <a href="http://wiki.shopify.com/Creating_an_app_and_deploying_it_to_Heroku_using_Rails_3" target="_blank">guide on Shopify's</a> site. The most important thing to do is run the <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">shopify_app</span> generate on a fresh Rails project, as it clobbers a bunch of stuff to give you a running app skeleton in record time.<br />
<br />
I really can't improve on it, so <a href="http://wiki.shopify.com/Creating_an_app_and_deploying_it_to_Heroku_using_Rails_3" target="_blank">go have a look at it</a> and come back when you're done. Go. Go now.<br />
<br />
<br />
<br />
<br />
<br />
...aaaaaaand we're back.<br />
<br />
<span class="Apple-style-span" style="font-size: large;">Environment Variables and Herkou</span><br />
The only thing I changed from the standard <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">shopify_app</span> generator was to move my environment variables (my app's Secret, Shopify Secret Token, and Shopify API keys) in to an external file which was NOT checked in to source control (Git). This meant I could host the project on GitHub for Fun and Profit, without giving up <b>mah secretz</b>.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://images.icanhascheezburger.com/completestore/2008/7/16/ihazbeenwatin128606953853140463.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="http://images.icanhascheezburger.com/completestore/2008/7/16/ihazbeenwatin128606953853140463.jpg" width="320" /></a></div>
<br />
<br />
I started out using <a href="http://tammersaleh.com/posts/managing-heroku-environment-variables-for-local-development" target="_blank">Tammer's steps</a>, but found that putting the load in <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">config/environment.rb</span> (as he suggests) this didn't load the variables in time for the Shopify config settings in <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">config/application.rb</span>. I ended up having to put the load in just before the Shopify config options are set (in <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">application.rb</span>), so it looks like this:<br />
<br />
<code> ...</code><br />
<br />
<code> # Heroku env variables - for development/test<br />
heroku_env = File.join(Rails.root, 'config', 'heroku_env.rb')<br />
load heroku_env if File.exists?(heroku_env)<br />
<br />
# Shopify API connection credentials:<br />
config.shopify.api_key = ENV['SHOPIFY_API_KEY']<br />
config.shopify.secret = ENV['SHOPIFY_SECRET']<br />
<br />
...<br />
</code><br />
<div>
<br /></div>
<div>
If anyone has a better way of doing this, please let me know (I tried a bunch of other stuff, but this was the only way which worked and wasn't too nasty). Once you've added that, you'll need to create a file config/heroku_env.rb with your secretz. Mine looks something like this:<br />
<br />
<code>
# DO NOT CHECK THIS FILE INTO VERSION CONTROL<br />
<br />
ENV['SHOPIFY_API_KEY'] = '12345678912345678912345678912345'<br />
ENV['SHOPIFY_SECRET'] = '12345678912345678912345678912345'<br />
ENV['SHOPIFY_SECRET_TOKEN'] = '12345678912345678912345678912345</code><span class="Apple-style-span" style="font-family: monospace;">12345678912345678912345678912345</span><span class="Apple-style-span" style="font-family: monospace;">12345678912345678912345678912345</span><span class="Apple-style-span" style="font-family: monospace;">12345678912345678912345678912345</span><span class="Apple-style-span" style="font-family: monospace;">'</span><br />
<code><br /></code><br />
Make sure you add the line <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">config/heroku_env.rb</span> to your <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">.gitignore</span> file, otherwise you're going to have a few issues when you deploy to Production... This setup also means you can use different values in the file to what you set in Heroku, and keep your prod and dev environments completely separate (== WINNING). It would also work well with things like AWS keys, and anything else you don't really want to be publicly visible on a GitHub-hosted project.<br />
<br />
<span class="Apple-style-span" style="font-size: large;">Making a Shopify App</span><br />
Once you've got that all down, you're ready to start making your own app. The important thing to remember with a Shopify App is that by "installing" your application on their store, all the store owner is doing is giving your app (in this case, a Rails app) permission to access <b>their Shopify data</b>. They're not actually copying any of your code, etc to their Shopify store.<br />
<br />
If you've set your application up as in the document above, store owners who install and log in to your application will be directed to the <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">home#index</span> action. Actually, they're being directed to the page they came from OR the root route (which by default is points to <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">home#index</span>). You can change this by modifying the root route in <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">config/routes.rb</span>, or change the final redirect (on success) in the <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">login#finalize</span> action (if you don't want to change the default route). You can also update the views that the <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">shopify_app</span> gem created for you in <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">app/views/home/</span>.<br />
<br />
The API is quite simple, and there's a few good examples in the default <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">home#index</span> view (<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">app/views/home/index.html.erb</span>). Once all the setup steps have been completed (in the <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">login</span> controller, provided by the Shopify gem), getting a list of the store's customers (once the owner has logged in) is as simple as:<br />
<br />
<code>
@customers = ShopifyAPI::Customer.find(:all)<br />
</code>
<br />
<br />
The same works for products, and a bunch of other resources. See a full listing of possible requests on the <a href="http://api.shopify.com/" target="_blank">API documentation page</a>. The magic happens with the <span style="font-family: 'Courier New', Courier, monospace;">around_filter</span> that Shopify gives you:<br />
<br />
<code>
around_filter :shopify_session<br />
</code>
<br />
<div>
<br /></div>
<div>
If you want to access Shopify data from your own controllers, just add this around filter to your controllers, and <b>get busy!</b></div>
<br />
<span class="Apple-style-span" style="font-size: large;">API Limit</span><br />
There's a limit of 500 API calls every 5 minutes, which is perfectly reasonable (there's a funny write-up about it <a href="http://wiki.shopify.com/Learning_to_Respect_the_API_calls_limit" target="_blank">on their wiki</a>). Even with a nice fat limit like that, requesting all the info you need every single time is LAME and SLOOOOW, so I stored some of the data locally for my own processing. That being said, I tired to store as little Shopify data in my app's database because I don't really want to be responsible for it - I keep just as much as is needed to make my app work.<br />
<br />
<span class="Apple-style-span" style="font-size: large;">Publishing the App</span><br />
I'm still putting the finishing touches on my app, but the <a href="http://en.wikipedia.org/wiki/Minimum_viable_product" target="_blank">MVP</a> is almost done - not bad for playing with the Shopify API/gems for only two days (along with my normal work). The next step in the plan is to get some shop owners to test and comment on the app, so that I can get <b>validated learning</b> - gotta <a href="http://theleanstartup.com/" target="_blank">keep it LEAN</a>. Hopefully it'll be in the <a href="http://apps.shopify.com/" target="_blank">Shopify App Store</a> soon, it's called (imaginatively!) <b><u>Customer Demographics</u></b>.</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2145974492412188882.post-45844498203300665692011-11-22T10:01:00.001-08:002011-11-22T10:06:35.263-08:00"WARNING: Cucumber-rails required outside of env.rb. The rest of loading is being defered until env.rb is called." with Bundler prerelease (1.1)Had a real 'fun' time (ie. not fun) getting around this error every time I tried to run 'bundle exec spork cucumber' (which would then die):<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Using Cucumber</span><br />
<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Preloading Rails environment</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">WARNING: Cucumber-rails required outside of env.rb. The rest of loading is being defered until env.rb is called.</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> To avoid this warning, move 'gem cucumber-rails' under only group :test in your Gemfile</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Loading Spork.prefork block...</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">undefined method `allow_rescue=' for ActionController::Base:Class (NoMethodError)</span><br />
<br />
I couldn't find any erroneous require's of cucumber-rails outside my <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">:test</span> group in my Gemfile, but eventually I stumbled across the solution in the comments of <a href="https://github.com/cucumber/cucumber-rails/pull/171">this pull request</a> (for a separate issue).<br />
<br />
I had to change the line in my Gemfile to:<br />
<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">gem "cucumber-rails", "~> 1.0", require: false</span><br />
<div>
<br /></div>
<div>
For the error message to go away, and spork to run properly. It seems to have been caused by a way the new (prerelease/1.1) version of Bundler loads gems - what a bitch (but it is a lot faster than the older versions, so I'm still using it).</div>
<br />
<div>
<br /></div>Unknownnoreply@blogger.com9tag:blogger.com,1999:blog-2145974492412188882.post-80735546688814003372011-11-16T10:43:00.001-08:002011-12-13T20:08:17.906-08:00Testing objects in Cucumberit always takes me a search and a few clicks to find this article on how to use FactoryGirl with Cucumber: <a href="https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md">https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md</a><br />
<br />
not. anymore.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2145974492412188882.post-60107265696382875642011-11-14T18:11:00.001-08:002011-11-15T06:20:53.373-08:00WARNING: i18n methods within step definitions are deprecatedWhen running some older step definition files with a newer version of Cukes, I kept getting the message "WARNING: i18n methods within step definitions are deprecated..." even though I couldn't see any il8n methods in my cucumber files.<br />
<br />
After a bit of digging, I found that you need to update your steps files so that you don't use any And/Then/When/Given methods inside your steps, and instead use the method <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">step</span> - but this only applies <b>inside</b> your step definitions. For example this:<br />
<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">When /^I sign in as "(.*)\/(.*)"$/ do |email, password|</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> Given %{I am not logged in}</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> When %{I go to the sign in page}</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> And %{I fill in "Email" with "#{email}"}</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> And %{I fill in "Password" with "#{password}"}</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> And %{I press "Sign in"}</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">end</span><br />
<br />
Changes to:<br />
<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">When /^I sign in as "(.*)\/(.*)"$/ do |email, password|</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> step %{I am not logged in}</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> step %{I go to the sign in page}</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> step %{I fill in "Email" with "#{email}"}</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> step %{I fill in "Password" with "#{password}"}</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> step %{I press "Sign in"}</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">end</span><br />
<br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2145974492412188882.post-28237862029114975972011-11-06T14:04:00.000-08:002011-11-06T14:04:42.092-08:00Even GitHub Loves Sctoch<div class="separator" style="clear: both; text-align: center;">
<a href="http://octodex.github.com/images/scottocat.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /><img border="0" height="320" src="http://octodex.github.com/images/scottocat.jpg" width="320" /></a></div>
<div style="text-align: center;">
Behold, <a href="http://octodex.github.com/images/scottocat.jpg"><b>ScottoCat</b></a>!</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2145974492412188882.post-56883275978796047122011-11-05T09:00:00.000-07:002011-11-06T14:04:54.716-08:00Using GitHub to get better at RubyAside from being a great site to host open source software, <a href="https://github.com/">GitHub</a> is a great place to review other people's code. By following all the repositories you're interested in, you get to see all their latest updates on your dashboard when you log in. I've found it useful for writing better specs/scenarios - when I get writer's block, I go look at some of the bigger Ruby-based projects on Github for ideas.<br />
<div>
<br /></div>
<div>
Another cool thing to do is search repos for specific gems/libraries that you are interested in using, or trying to get your head around. When you search GitHub, you can do a search with very specific parameters.<br />
<br /></div>
<div>
For example: Search "<i>Code</i>" with language "<i>Ruby</i>" and term "<i>require savon</i>" to see other projects using the <a href="http://savonrb.com/">Savon</a> gem - because consuming SOAP services in Ruby are so much fun! I mean, it's almost as good as getting teeth pulled... (Savon makes it bearable)</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2145974492412188882.post-55899311881081636682011-11-04T07:20:00.000-07:002011-11-06T14:05:20.168-08:00Rails 3.1, Spree, and "rake aborted! Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes"<br />
I keep getting the following error when trying to run Rails 3.1 with Spree commerce, right when running my first rake command '<i>rake db:create</i>':<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">$ rake db:create</span><br />
<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">rake aborted!</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">(See full trace by running task with --trace)</span><br />
<div>
<br /></div>
<br />
The solution is to manually add the following gems to your gem file (and run the obligatory '<i>bundle install</i>' afterwards):<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">gem 'execjs'</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">gem 'therubyracer'</span><br />
<div>
<br /></div>
<div>
Hope that helps.</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2145974492412188882.post-71665260428766806682011-11-02T11:09:00.000-07:002011-11-06T14:06:11.363-08:00Bundle Install gives Gem::Exception: Cannot load gem atWhile trying to install someone else's Rails 3.0.x app on my dev server, the 'bundle install' command kept failing, with an error about the cache location for gems.<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">$ bundle install</span><br />
<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Fetching source index for http://rubygems.org/</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Gem::Exception: Cannot load gem at [/usr/lib/ruby/gems/1.9.1/cache/rake-0.8.7.gem] in /home/rowan/newprj</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">An error occured while installing rake (0.8.7), and Bundler cannot continue.</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Make sure that `gem install rake -v '0.8.7'` succeeds before bundling.</span><br />
<div>
<br /></div>
<div>
After reading a <a href="http://stackoverflow.com/questions/4980223/ror-bundler-problem">StackOverflow post</a> on a similar error message I found that the way around it is to do a bundle install as root:</div>
<div>
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">$ sudo bundle install</span></div>
<div>
<br /></div>
<div>
<b>This isn't the right way to do it normally</b>, and I don't recommend it, but it does seem to be necessary at the moment because Ubuntu (11.x) has Ruby 1.9.2 packaged under the 1.9.1 label/location.</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2145974492412188882.post-26393399521300404412011-11-01T13:29:00.000-07:002011-11-06T14:06:36.387-08:00We don't need no stinkin' web steps!I spent my first attempts back in BDD-land wondering why all the examples I was reading kept referring to Capybara's web_steps.rb file, and why I didn't have it. It all made sense when I finally found <a href="http://aslakhellesoy.com/post/11055981222/the-training-wheels-came-off">this article by Aslak</a>.<br />
<br />
The file web_steps.rb was originally in Webrat (which is what I used last time I was doing Rails apps in Rails 2.3). It contained a bunch of pre-defined, regex-dependent steps which could be incorporated in to your scenarios for quick development of - but ultimately limiting - your scenarios.<br />
<br />
Read the article for the full reasons behind it. It seems a bit of an inconvenience for someone starting out, but seeing as Aslak <b>created Cucumber</b>, I'm not going to argue with him about the finer points of BDD.<br />
<br />
The <a href="https://github.com/jnicklas/capybara">Capybara API</a> is what you should be using instead to replace web_steps.rb functionality in the future.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2145974492412188882.post-2696615195208136592011-10-31T11:23:00.000-07:002011-10-31T11:24:51.278-07:00Forcing the system update command for ruby gems on Ubuntu 11.04If you try run Ruby Gem's command to update itself (<i>$ sudo gem update --system</i>) on Ubuntu you get a pretty stern warning that it's not recommended, and you might have issues blah blah blah.<br />
<br />
There's a bunch of gems which complain if your gem version is out of date (and the default version with Ubuntu is), and I don't know when the official package will be updated.<br />
<br />
Just so I know for next time, the command to force it to upgrade (<b>at your own risk</b>) is:<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">$ sudo REALLY_GEM_UPDATE_SYSTEM=1 gem update --system</span><br />
<br />
I haven't had any problems from this on 11.04, but as always YMMV.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2145974492412188882.post-20024286624857315452011-10-30T12:07:00.000-07:002011-10-30T12:07:13.219-07:00Getting VCR to work with RspecI'm writing an SOAP API wrapper in Ruby, and there's no test system to use during development. Being about to use something like <a href="https://github.com/myronmarston/vcr">VCR</a> to record the request/response from the service is great, because I can do it a controlled fashion the first time (and record it), and then do stupid things to it without getting in to trouble. It also helps my features and tests run <b>much</b> faster than if I had to actually ping the server every time.<br />
<br />
I found <a href="http://cukes.info/">Cucumber</a> and VCR's <a href="https://www.relishapp.com/myronmarston/vcr/docs/test-frameworks/usage-with-cucumber">official documentation</a> good, but over-complicated for what I wanted to do. Here are the steps it actually took me to get it working quickly and simply in my features (using <a href="https://github.com/chrisk/fakeweb">fakeweb</a>).<br />
<div>
<ol>
<li>Create the file 'features/support/vcr.rb' with the following contents:</li>
<code>
require 'vcr'<br />
<br />
VCR.config do |c|<br />
c.stub_with :fakeweb<br />
c.cassette_library_dir = 'features/cassettes'<br />end<br />
</code>
<li>Inside the step definitions (in my steps files under 'features/steps/'):</li>
<code>
VCR.use_cassette 'name' do<br /> ...<br />
end</code>
</ol>
<div>
This will create the cassette file 'name' in the 'features/cassettes' directory. After recording your request/response the first time, any additional communications will be stopped by VCR, because the default options for VCR sets record to 'new episodes'.</div>
</div>Unknownnoreply@blogger.com0