Flash not accessible in tests (TypeError: can’t convert String into Integer)

Posted about 1 year back at zargony.com

This morning I faced a strange problem when trying to write RSpec tests for a user login action. Trying to setting the flash before doing a request, resulted in an unexpected Exception:

1)
TypeError in 'SessionController logging in with correct credentials should redirect to the url_after_login url if given'
can't convert String into Integer
.../vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/functional.rb:80:in `flash'
./spec/controllers/session_controller_spec.rb:52:
./script/spec:4:

(more…)

Flash not accessible in tests (TypeError: can't convert String into Integer)

Posted about 1 year back at zargony.com

This morning I faced a strange problem when trying to write RSpec tests for a user login action. Trying to setting the flash before doing a request, resulted in an unexpected Exception:

1)
TypeError in 'SessionController logging in with correct credentials should redirect to the url_after_login url if given'
can't convert String into Integer
.../vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/functional.rb:80:in `flash'
./spec/controllers/session_controller_spec.rb:52:
./script/spec:4:
Read more »

Flash not accessible in tests (TypeError: can't convert String into Integer)

Posted about 1 year back at zargony.com

This morning I faced a strange problem when trying to write RSpec tests for a user login action. Trying to setting the flash before doing a request, resulted in an unexpected Exception:

1)
TypeError in 'SessionController logging in with correct credentials should redirect to the url_after_login url if given'
can't convert String into Integer
.../vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/functional.rb:80:in `flash'
./spec/controllers/session_controller_spec.rb:52:
./script/spec:4:
Read more »

Shirt Reader (#140)

Posted about 1 year back at Ruby Quiz

Sun Microsystems handed out some fun shirts at the LSRC. The graphic on the front looks something like:

sun image

star image + T + up arrow

E + perfume bottle image + sea shells image

This is a clever advertisement for their "Sun Startup Essentials" program.

This week's Ruby Quiz is to write a program that can read such shirts. At the basic level, we will assume the user will feed us the right words:

$ ruby read_shirt.rb e scent shells
essentially

Hopefully your solution will be smarter than mine, which, as you can see, only gets close. It may be better to give a few possible choices instead of just the best match.

Of course, the problem comes when you guess the wrong word. My first thought was of a perfume bottle, as my description shows, but the correct word was scent. For bonus points, see what you can do about this problem. One idea might be to allow alternatives for a segment of the word. Another might be to hit the thesaurus, which does list scent as a synonym for perfume.

Ruby on Rails Security Guide

Posted about 1 year back at Ruby Inside

Nakul Aggarwal and Ritesh Arora have put together a concise, to the point, Ruby on Rails Security Guide that looks at how to tackle security issues in your authentication system, models, controllers, views, and elsewhere. Lots of links, lots of tips, and a must-read for anyone who's not feeling 100% confident in the security of their Rails app.

Testing: Frameworks are evolving

Posted about 1 year back at Jay Fields Thoughts

Test-Driven Development was introduced to me by way of xUnit frameworks.

In the beginning, all xUnit frameworks looked very much the same. All tests lived within a class that inherited from an abstract test case class, and all tests were defined by creating a method that begin with the word test. However, as time progressed the xUnit frameworks began to take advantage of features specific to individual languages.

Martin Fowler's bliki entry Xunit contains a description of how NUnit matured.

The first version of NUnit even had a "isVAforJava" method which originated in special handling for Visual Age for Java. Others have been more sophisticated: NUnit 2.0 was praised by Anders Heljsberg for its use of attributes in C#.
Utilizing language specific features was the first step; however, as testing methods mature it's becoming more clear that the features of xUnit also need to mature.

The first framework I noticed that decided to start breaking rules was RSpec. The 1.0 version of RSpec provided a new syntax for defining test cases and for defining assertions. The following example shows how you would write the same test in Test::Unit (a traditional xUnit framework) and RSpec.

# RSpec 
describe Bowling do
before(:each) do
@bowling = Bowling.new
end

it "should score 0 for gutter game" do
20.times { @bowling.hit(0) }
@bowling.score.should == 0
end
end

# Test::Unit
class BowlingTest < Test::Unit::TestCase
def setup
@bowling = Bowling.new
end

def testShouldScoreZeroForGutterGame
20.times { @bowling.hit(0) }
assert_equal 0, @bowling.score
end
end

I do believe that the RSpec version is more semantically pleasant. However, given a programmer who practices TDD, when they maintain tests they use an xUnit clone, then I'm not sure the semantic benefit is worth learning a new framework. At least, I wasn't at first.

Another new xUnit framework is xUnit.net, announced recently on James Newkirk's blog. xUnit.net excites me more than any other piece of software that I'm likely to never use. I'll probably never use it since I don't plan on going back to .net development, but the features are exciting nonetheless. James et al have taken their test-driven development experiences and created a framework that guides them towards writing better tests. James' entry gives the full details (which I suggest reading even if you never plan on doing any .net work), but a few features I like are the removal of setup and teardown, and the aspect-like functionality. You may be less impressed since Ruby provides aspect-like functionality very easily, but I believe it's nice to see a xUnit framework built with extension points in mind.

These new frameworks are exciting because they are incorporating lessons learned from the past few years of practicing test-driven development. As our experience with TDD grows, so should our tools.

Apple Wireless Keyboard

Posted about 1 year back at poocs.net - Home

Apple Wireless Keyboard

Apple announced new keyboards alongside its new iMacs in early August, but the bluetooth variant wasn’t shipping until mid-September. As you can see, mine just shipped (I’ve been using Apple bluetooth keyboards since they first came out).

When you initially open the package, these things really seem tiny. But in the end, they’re exactly the size as the thicker older model minus the numeric keypad and cursor keys moved over.

With regards to the touch feel (and I’m typing this on the keyboard you see above), they feel different but I can type quick and fast easily. The keyboard of my MacBook Pro still feels a little softer and typing on the old whitish Apple keyboards is a different deal altogether. The lowered height of the device is definitely a welcome change.

So far I don’t miss the numeric keypad (and I’m far from being an accountant). The only thing I have to mentally adjust for is the lack of an enter key right next to where I keep the mouse. Due to the smaller size, my mouse currently lives quite a bit to the right and I tended to hit that extra enter key with my right hand occasionally when reaching over from the mouse. This hits solid table ground for the time being. But I’ll live.

Keyboard Update 1.2 popped up when checking with Software Update after pairing the keyboard, installed and rebooted, the new keys for Dashboard and iTunes (play/pause/skip) worked immediately. So no issues to report there.

Is it too late for Parrot VM?

Posted about 1 year back at InfoQ Personalized Feed for unregistered user - Register to upgrade!

The Parrot Virtual Machine recently had it’s sixth birthday. Parrot is a VM that sprung out of the Perl6 development, which primarily targets dynamic languages, but also for instance .NET and C99. But six years is a long time, and both Microsoft and Sun is targeting this segment. Is it too late for Parrot?

RailsConf EU 2007 Wrap Up

Posted about 1 year back at Ruby Inside

Ichbin
(photo credit: dwortlehock)

RailsConf Europe 2007 is over and it's time to wrap up. As before, there are oodles of pictures on Flickr with the "RailsConfEurope" tag (yah-boo to you miserable sods who don't use Creative Commons licenses for your photos) and DHH points to all of the presentations given at the conference (covering areas as wide as Ferret, REST, Adobe Flex, Amazon S3 and JRuby). Continuing from his fine coverage of Monday, the first day of the conference, Robert Dempsey succinctly wraps up the Tuesday morning and afternoon sessions, as well as the Wednesday morning sessions, and then Wednesday in its entirety. These are worth a read if you didn't go, as he provides some context missing elsewhere.
Last but not least, David Heinemeier Hansson's keynote. The King of Rails seemed to focus mostly on Rails 2.0, which will be more of an evolutionary step than a revolutionary one. Casper Fabricus has a superb writeup with many choice quotes and code examples, although Nick Sieger has done a good job too. On his own blog, however, the King decided to post his views of Sun's ever-growing support for Ruby and Rails and his ultimate satisfaction at the success of RailsConf in general.

New

Posted about 1 year back at Sneaky Abstractions

I always thought new Class was too much like Java..

Function.prototype.new = function(){
  function F(){};
  F.prototype = this.prototype;
  var o = new F();
  this.apply(o, arguments);
  return o;
};

function Cat (name) {
  this.name = name;
};

Cat.prototype.greet = function(){
  return "Hello, my name is " + this.name;
};

var garfield = Cat.new("Garfield");
garfield.greet(); // "Hello, my name is Garfield"

Just like Ruby! I know, I know, “new” is a reserved word.. For some reason it works just fine in Firefox, but you can just as well call it “create” or “spawn”, or “beget”. I’m sure it’s still a pretty bad idea to begin with, and I can’t see any advantages at all with it. It’s just that I have a strong dislike for keywords.

Rails tool space is heating up

Posted about 1 year back at Riding Rails - home

There’s a lot of action going on in the Rails IDE space these days. Besides Aptana RadRails, which has been around for a long time, Sun’s got impressive Rails support in the new NetBeans, and just this week CodeGear launched their 3rdRail IDE, which also looks like a great setup.

I’m personally not quite ready to leave TextMate behind, but it’s encouraging to see all these options for dedicated Rails IDEs. It’s not going to be long before they’ll be giving regular text editors a serious run for their money.

Rails tool space is heating up

Posted about 1 year back at Riding Rails - home

There’s a lot of action going on in the Rails IDE space these days. Besides Aptana RadRails, which has been around for a long time, Sun’s got impressive Rails support in the new NetBeans, and just this week CodeGear launched their 3rdRail IDE, which also looks like a great setup.

I’m personally not quite ready to leave TextMate behind, but it’s encouraging to see all these options for dedicated Rails IDEs. It’s not going to be long before they’ll be giving regular text editors a serious run for their money.

RailsConf EU '07 is over

Posted about 1 year back at Riding Rails - home

The party in Berlin came to an end all too soon. I had a blast there and so did everyone else it seemed. Such a fantastic atmosphere and group of people. If you weren’t able to make it, you can peruse the presentation slides or the pictures. Thanks to everyone who made it possible and to all that was able to come.

RailsConf EU '07 is over

Posted about 1 year back at Riding Rails - home

The party in Berlin came to an end all too soon. I had a blast there and so did everyone else it seemed. Such a fantastic atmosphere and group of people. If you weren’t able to make it, you can peruse the presentation slides or the pictures. Thanks to everyone who made it possible and to all who was able to come.

Rails: Where do you require?

Posted about 1 year back at Jay Fields Thoughts

I was recently looking over a codebase and noticed that several different files contained require statements. I'm not talking about the require statement that each test file has, I'm taking about seeing require 'ostruct', require 'enumerator' or require 'soap4r' in numerous class definitions.

For the last few projects I've been following the convention of putting all the require statements in environment.rb. There are more efficient strategies, but I find this to be the most maintainable of the solutions I've tried.

While following the above strategy I haven't run into any issues with two libraries defining behavior on differing classes that are named the same, but I have heard concerns from team members on the time it takes to require each library. I think that's a valid concern and I was planning on addressing it by writing a method that takes an array of strings and requires them one at a time. The new method would also benchmark each require and print a warning if the require is taking an unacceptable amount of time.

Please drop me a line (or blog it and leave a link) in the comments if you have a strategy that's worked well for you.


1 ... 468 469 470 471 472 ... 575