{"id":231,"date":"2010-09-11T22:34:37","date_gmt":"2010-09-12T04:34:37","guid":{"rendered":"https:\/\/www.chrisedwards.dreamhosters.com\/blog\/2010\/09\/11\/creating-a-new-gemspec-for-the-nubular-project-nu-is-easier-than-you-might-think\/"},"modified":"2011-08-21T14:51:20","modified_gmt":"2011-08-21T20:51:20","slug":"creating-a-new-gemspec-for-the-nubular-project-nu-is-easier-than-you-might-think","status":"publish","type":"post","link":"http:\/\/architester.com\/blog\/2010\/09\/11\/creating-a-new-gemspec-for-the-nubular-project-nu-is-easier-than-you-might-think\/","title":{"rendered":"Creating a new gemspec for the Nubular Project (Nu) is easier than you might think"},"content":{"rendered":"<p>I just started using <a title=\"The Nubular Project Wiki\" href=\"http:\/\/nu.wikispot.org\/\" target=\"_blank\">Nu<\/a> to manage the dependencies in my <a title=\"Fluency project on GitHub\" href=\"http:\/\/github.com\/ChrisEdwards\/Fluency\" target=\"_blank\">Fluency<\/a> project. I had used package managers for ruby and php in the past, and loved them, so I couldn\u00e2\u20ac\u2122t pass up the opportunity to try out Nu. I am glad I did.<\/p>\n<h2>What the heck is Nu?<\/h2>\n<p>Nu is a package manager for .NET (finally!). It allows you to install code libraries and all their dependencies automatically, and keep them updated. If you have ever heard of <a title=\"RubyGems.org your community gem host.\" href=\"http:\/\/rubygems.org\/\" target=\"_blank\">RubyGems<\/a>, this is the same thing. In fact, its built on top of ruby gems! <\/p>\n<h2>Installing Nu<\/h2>\n<p>To use Nu, you first need to install ruby. You can get it <a title=\"Ruby installer for windows.\" href=\"http:\/\/rubyforge.org\/frs\/download.php\/71078\/rubyinstaller-1.9.1-p378.exe\" target=\"_blank\">here<\/a>. Then upgrade RubyGems by dropping to a command prompt and typing<\/p>\n<p><code>gem update --system<\/code> <\/p>\n<p>Then to install Nu you type<\/p>\n<p><code>gem install nu<\/code> <\/p>\n<p>And that\u00e2\u20ac\u2122s it\u00e2\u20ac\u00a6Nu is installed and ready to go.<\/p>\n<h2>Using Nu<\/h2>\n<p>Using Nu is dirt simple. Wanna install NUnit?<\/p>\n<p> <code>C:\\project&gt;<b>nu install nunit<\/b>     <br \/>Gem nunit is not installed locally - I am now going to try and install it     <br \/>Successfully installed nunit-2.5.7.10213.20100801     <br \/>Installed package nunit.<\/code>   <\/p>\n<p>Done! How about NHibernate?<\/p>\n<p> <code>C:\\project&gt;<b>nu install nhibernate<\/b>    <br \/>Gem nhibernate is not installed locally - I am now going to try and install it    <br \/>Successfully installed nhibernate-2.1.2.4000    <br \/>Loading dependency: castle.core = 1.1.0.0    <br \/>Loading dependency: castle.dynamicproxy2 = 2.1.0.0    <br \/>Loading dependency: castle.core = 1.1.0.0    <br \/>Loading dependency: log4net = 1.2.10.0    <br \/>Installed package nhibernate.<\/code>   <\/p>\n<p>Sure beats the pants off navigating out to the website to download the latest version, doesn\u00e2\u20ac\u2122t it? And it even installed all the dependencies.<\/p>\n<p><a href=\"https:\/\/www.chrisedwards.dreamhosters.com\/blog\/wp-content\/uploads\/2010\/09\/image.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/www.chrisedwards.dreamhosters.com\/blog\/wp-content\/uploads\/2010\/09\/image_thumb.png\" width=\"209\" height=\"123\" \/><\/a> <\/p>\n<h2>Creating a gem to be installed using Nu<\/h2>\n<p>So what does it take to make a project installable using Nu? Not much. I was surprised at how easy it was. <\/p>\n<p>When I converted Fluency to install all its dependencies using Nu, I found one library that that wasn\u00e2\u20ac\u2122t yet packaged as a gem and installable through Nu. This was the <a title=\"SharpTestsEx on CodePlex\" href=\"http:\/\/sharptestex.codeplex.com\/\" target=\"_blank\">SharpTestsEx<\/a> library. So I did what any self-respecting supporter of open-source software would do, I decided to add it myself so anyone else could use it.<\/p>\n<h3>1. Prepare the gemspec<\/h3>\n<p>To do this, I created a gems folder and in it, a <a title=\"Gemspec::reference\" href=\"http:\/\/docs.rubygems.org\/read\/chapter\/20\" target=\"_blank\">gemspec<\/a> file \u00e2\u20ac\u0153sharptestsex.gemspec\u00e2\u20ac\u009d with the following contents<\/p>\n<pre class=\"ruby\" name=\"code\">version = File.read(File.expand_path(&quot;..\/VERSION&quot;,__FILE__)).strip\r\n\r\nGem::Specification.new do |spec|\r\n  spec.platform    = Gem::Platform::RUBY\r\n  spec.name        = 'sharptestsex'\r\n  spec.version     = version\r\n  spec.files = Dir['lib\/**\/*']\r\n  \r\n  spec.summary     = 'Sharp Tests Ex - .NET Fluent Assertions for Your Tests'\r\n  spec.description = '#TestsEx (Sharp Tests Extensions) is a set of extensible extensions. The main target is write short assertions where the Visual Studio IDE intellisense is your guide. #TestsEx can be used with NUnit, MsTests, xUnit, MbUnit.'\r\n  \r\n  spec.authors           = ['Fabio Maulo','JDiamond']\r\n  spec.email             = ''\r\n  spec.homepage          = 'http:\/\/sharptestex.codeplex.com\/'\r\n  spec.rubyforge_project = 'sharptestsex'\r\nend<\/pre>\n<p>and a \u00e2\u20ac\u0153VERSION\u00e2\u20ac\u009d file that simply contained the version number<\/p>\n<pre class=\"ruby\" name=\"code\">1.0.0.0<\/pre>\n<p>I then created a gems\/lib\/ folder and placed the binaries in it. The spec.files attribute indicates that I want to include all the files in this folder in the gem.<\/p>\n<h3>2. Build and test the gem locally.<\/h3>\n<p>Then I built the gem at the command prompt with<\/p>\n<p><code>gem build sharptestsex.gemspec<\/code> <\/p>\n<p>This will product the gem file names sharptestsex-1.0.0.0.gem. I tested it with nu locally by installing the gem directly (without going to the rubygems server) by specifying the filename of the gem.<\/p>\n<p><code>gem install sharptestsex-1.0.0.0.gem<\/code> <\/p>\n<p>This installed it from my local drive into the gem cache. The gem cache is where nu gets the libraries. If nu does not find the requested library in the gemcache, it asks rubygems to get it from the server. Installing it like I did above ensured its in the cache so nu could find it. Then I tested that nu could install it.<\/p>\n<p><code>nu install sharptestsex<\/code> <\/p>\n<p>Once I saw it all worked, I uninstalled the gem so that I would be able to test that it pulls from the server. Uninstalling the gem deletes it from the local gemcache. I had to do this because if it existed in the cache, it wouldn\u00e2\u20ac\u2122t even try to download if from the server the next time I test it. I uninstalled it with\u00e2\u20ac\u00a6<\/p>\n<p><code>gem uninstall sharptestsex<\/code><\/p>\n<h3>3. Push the gem to RubyGems.org<\/h3>\n<p>Now I was ready to push the gem out to <a href=\"http:\/\/rubygems.org\" target=\"_blank\">RubyGems.org<\/a>. To do that, I needed to sign up for a free account, which was quick and painless. The I pushed the gem up.<\/p>\n<p><code>gem push sharptestsex-1.0.0.0.gem<\/code><\/p>\n<p>I was prompted for my RubyGems.org login and password, and then the gem was uploaded.&#160; <\/p>\n<h3>4. The final test<\/h3>\n<p>Then my new gem is ready to install with nu! I tested it with\u00e2\u20ac\u00a6<\/p>\n<p><code>nu install sharptestsex<\/code><\/p>\n<p>I checked, and sure enough, I saw a lib folder that contains a sharptestsex folder with all the binaries. It was way easier than I thought.<\/p>\n<h3>Resources<\/h3>\n<p>I drew heavily from the following resources while getting this to work.<\/p>\n<ul>\n<li><a href=\"http:\/\/devlicio.us\/blogs\/rob_reynolds\/archive\/2010\/07\/16\/how-to-gems-and-net.aspx\" target=\"_blank\">How To: Gems and .NET<\/a> \u00e2\u20ac\u201c <em>Rob Reynolds, \u00e2\u20ac\u0153The Fervent Coder\u00e2\u20ac\u009d<\/em> <\/li>\n<li><a href=\"http:\/\/weblogs.asp.net\/bsimser\/archive\/2010\/07\/30\/creating-a-quot-new-quot-gem-for-quot-nu-quot-from-0-to-100-in-24-hours.aspx\" target=\"_blank\">Creating a &quot;New&quot; Gem for &quot;Nu&quot; &#8211; From 0 to 100 in 24 Hours<\/a> \u00e2\u20ac\u201c <em>Bill Simser<\/em> <\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I just started using Nu to manage the dependencies in my Fluency project. I had used package managers for ruby and php in the past, and loved them, so I couldn\u00e2\u20ac\u2122t pass up the opportunity to try out Nu. I am glad I did. What the heck is Nu? Nu is a package manager for [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,31],"tags":[79,30],"class_list":["post-231","post","type-post","status-publish","format-standard","hentry","category-net","category-c","tag-net","tag-csharp"],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/posts\/231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/comments?post=231"}],"version-history":[{"count":3,"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/posts\/231\/revisions"}],"predecessor-version":[{"id":362,"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/posts\/231\/revisions\/362"}],"wp:attachment":[{"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/media?parent=231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/categories?post=231"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/tags?post=231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}