Is there an Expect equivalent gem for Ruby?
Ruby comes with the PTY module for setting up pseudoterminals to drive interactive command line applications. With it comes an expect
method that allows you to interact with an application kinda like Expect. For learning how to use expect, I found "What to expect from the Ruby expect library?" helpful.
As far as gems go, maybe checkout greenletters which is supposed to improve upon PTY + expect (although I haven't tried it myself).
Any good Ruby console application gems out there?
Here's some console related gems I've written you may like:
- bond - Custom readline autocompletion of methods, arguments and more.
- hirb - Framework for formatting ruby objects. Comes with tables, trees, selection menus and a smart pager.
- alias - Creates, manages and saves aliases for class methods, instance methods, constants, delegated methods.
Is there an rspec matcher to confirm a class includes a library, module or gem?
Testing if a class has included a module is generally wrong, as you are testing implementation details instead of expected behavior.
Included modules can be found by calling ancestors
on the class, so you can simply use include
matcher:
expect(Dish::Player.ancestors).to include(HTTParty)
Your second expectation should be tested with:
expect(Dish::Player.base_uri).to eq 'http://api.dribbble.com'
EDIT
Until today I did not know that classes implement the <=>
operator. You can simply check if Dish::Player < HTTParty
.
Is there an equivalent of Don Libes's *expect* tool for scripting interaction with web pages?
You might be looking for Selenium
Using Ruby Enterprise Edition, gems are not installed where I would expect
There's a good explanation of what's going on here:
sudo changes PATH - why?
This assumes you're using Ubuntu. sudo does change the path under ubuntu.
The gem you have in /usr/bin/ is probably a symlink to /usr/bin/gem1.8. What I did was symlink ruby-enterprise's gem to /usr/bin/ree-gem like this:
sudo ln -s /opt/ruby-enterprise-1.8.6-20090201/bin/gem /usr/bin/ree-gem
then I just use:
sudo ree-gem install some_gem
to install gems specifically for ree. If you're not using the ruby 1.8.6 rubygem, you can symlink REE's gem to /usr/bin/gem instead:
sudo ln -s /opt/ruby-enterprise-1.8.6-20090201/bin/gem /usr/bin/gem
How do you get a ruby gem into the include path for require
It's actually not to hard to do this manually. Let's say you have a library whatever.rb
that you want to distribute as a gem.
- make a directory
lib
and put a copy ofwhatever.rb
inlib/whatever.rb
. - make a file
whatever.gemspec
, and put the following in there, filling in the appropriate values:
Gem::Specification.new do |spec|
spec.name = 'the-name-of-your-gem'
spec.version ='0.0.1'
# this is important - it specifies which files to include in the gem.
spec.files = ["lib/whatever.rb"]
# optional, but useful to your users
spec.summary = "A more longwinded description of your gem"
spec.author = 'Your Name'
spec.email = 'you@yourdomain.com'
spec.homepage = 'http://www.yourpage.com'
# you did document with RDoc, right?
spec.has_rdoc = true
# if you have a ruby forge project
spec.rubyforge_project = 'your-project-name-on-rubyforge'
# if you have any dependencies on other gems, list them thusly
spec.add_dependency('hpricot')
spec.add_dependency('log4r', '>= 1.0.5')
end - now, to build the gem, use the
gem build
command:
% gem build whatever.gemspec
Successfully built RubyGem
Name: the-name-of-your-gem
Version: 0.0.1
File: the-name-of-your-gem-0.0.1.gem
% - You can test locally by using
gem install the-name-of-your-gem-0.0.1.gem
To use your library in a script then, simply do the following at the top:
require 'rubygems' # puts gem libraries in the require path
require 'whatever' # loads your library
For more on what the various settings in the gemspec
file, check the GemSpec Reference.
Personally, I use rubygems a lot to package executable scripts as well, and find it very handy for that.
Related Topics
Rails with Ruby-Debugger Throw 'Symbol Not Found: _Ruby_Current_Thread (Loaderror)'
Using Join Tables in Ruby on Rails
How to Know When to "Refresh" My Model Object in Rails
How to Alter the Timezone of a Datetime in Ruby
Actionview::Template::Error (Incompatible Character Encodings: Utf-8 and Ascii-8Bit)
What's the Difference Between Colon ":" and Fat Arrow "=>"
Shell Out from Ruby While Setting an Environment Variable
How to Know What Is Not Thread-Safe in Ruby
Ruby on Rails Plural (Controller) and Singular (Model) Convention - Explanation
How to Pass Multiple Arguments to a Ruby Method as an Array
Geocoder, How to Test Locally When Ip Is 127.0.0.1
Why Is _File_ Uppercase and _Dir_ Lowercase
How to Save an Object to a File
Using Ruby Convert Numbers to Words
How to Install JSON Gem - Failed to Build Gem Native Extension(MAC 10.10)
Heroku and Rails: Gem Load Error with Postgres, However It Is Specified in Gemfile
File.Expand_Path("../../Gemfile", _File_) How Does This Work? Where Is the File