Entries categorized as ‘programming’
I just upgraded one of my Rails projects to Rspec 1.0.2, ran all my old specs to see what would happen, and … crunch. It turns out there are a few gotchas if you were using an older version (instead of starting from scratch–I think they’ll be picking up some new users with this release).
First thing to change in your specs:
context "a model or controller or whatever" do
specify “behavior” do
…
end
end
is now
describe "a model or controller or whatever" do
it “has behavior” do
…
end
end
The description for model blocks should look like:
describe Apple, "with fixtures loaded" do
…
end
The string after the model name is optional.
For controller blocks it’s:
describe ApplesController do
…
end
You can also use a string in place of the controller name, in which case you’ll need to declare the controller name explicitly.
describe "Submitting new apple description"
controller_name :apples
…
end
The setup block is now before(:each).
before(:each) do
[setup actions of some sort]
end
The syntax for ’should’ functions has changed.
I had several examples of:
User.should_respond_to(:authenticate)
This is now:
User.should respond_to(:authenticate)
Note the lack of an underscore after ’should’.
The exception to that is the should_not function.
This is correct:
@feed.posts.should_not be(nil)
With these changes, all of my specs are passing again. Did I miss anything that broke for you? Leave a comment.
Links to further documentation:
Writing specs for Rails
General Rspec instructions
Categories: bdd · programming · rails · rspec · ruby · testing · tips · upgrade
From _why’s Hackety Manifesto:
Hello world should be one line.
In fact, downloading an MP3 should be one line!!
We just don’t care right now, do we? Programmers have a paid gig. So business is happily slurping them up. Look at our books. Look at the programming sites. Programming is tightly coupled to business. Often the first example is an e-commerce site! Our books are like FIFTY DOLLARS!! For crying out loud.
This diatribe isn’t about business being bad. Of course you need to feed your family and drive an Audi.
This diatribe is about adding some balance to the world of programming. Okay, so, let’s take things into our own hands and bring hacking to the young folks.
Go read the rest of it. The bylaws are wonderful.
Categories: accessiblity · hackety hack · manifesto · programming
I don’t personally know a single female Ruby or Rails developer. The only one I’ve even heard of is Amy Hoy, and I didn’t really get a chance to talk to her at FOSCON, so it would be stretching things to say we’ve met.
I’m not talking about professional developers, even. I’m looking for anyone who has started a Rails app or played around with Ruby for a weekend or two. And I’m active with the local Ruby Brigade, I read other developers blogs, I search through lists of conference and event attendees.
Nothing. What’s going on here? Ruby is a rapidly growing field, as demonstrated by how quickly the conferences sell out, the number of new books released just in the last year, the number of businesses who know little about web development frameworks but are actively looking for Rails development because they heard it was good. This is an area where the interested developer can get in and have so many opportunities to do neat things. If there isn’t room for women here, then where?
Don’t take this to mean that I really think there are no other women in my field (even “the only female Ruby developer in Oregon” seems pretty drastic). But I don’t know where to find them. I’m sure that the number of developers in any area who are active in their local tech community is a small part of the total, and the number who become visible in a national or global arena, even online, is even smaller. Still, this suggests that women are such a small portion of the total field that by the time you filter down through these other criteria, they essentially disappear.
I think at least part of what I’m seeing is likely to occur in any part of the tech industry that hasn’t hit the corporate mainstream. This is an environment that weeds women out at all levels, to the point that the number who stick around long enough (or get involved deeply enough) to learn that there’s more out there than just Java or C++ is tiny, especially compared to those who enroll in beginning programming classes.
I’m very frustrated when I start to think about this too long, because I believe I belong here. And if I do, other women should be here too. Software is too big a part of modern life to let it be created by only one segment of the population.
[as a footnote, I stole the "where are the women" tag from Anne Zelenka, who has been using it on her blog and on del.icio.us to talk about women in blogging, the tech industry, etc.]
Categories: gender · programming · ruby · where are the women
I’m feeling completely worn out from spending my afternoon sorting out problems with the login controller on one of our projects. It was in a very messy state, containing a partially removed acts_as_authenticated, and the net result was that you couldn’t log in at all (don’t worry, it’s in an early stage of development. No actual users were harmed). After a few hours of clearing out code that was no longer useful and rewriting the rest from scratch, I think I’ve managed to replace it with a much smaller set of code that handles salted password hashes correctly and redirects the logged in user to an appropriate section of the site. More testing will be required.
I’ve learned that I’m happiest when my daily work involves lots of problems and questions to resolve. Not the bad interpersonal “my manager is an asshole” problems, but things like “how do we make it so that the user can create a blog with these features?” I like the aha moments that come when you’ve been staring at something for a while, and suddenly realize you actually understand why the example code is written the way it is, and how to apply it to your project. The downside is that after a full day of this, I feel like taking a very long nap.
Another cool thing I’m discovering at the new job is that I really like working with a team of programmers. I haven’t had a lot of opportunities to code on group projects, but it’s very nice to be able to talk to other people when I’m trying to decide how to approach the next problem. It’s an even nicer resource when my code is producing errors I haven’t seen before.
There were a lot of things about the old job that felt disempowering. We often heard other people describe our group as “just babysitting the data” or “not technical like the programmers”, and the general attitude was that other people were more qualified to decide for us how software functions we used on a daily basis ought to be designed. I really like being in an environment where I feel like I can just go ahead and get things done, because people trust me to figure it out or ask questions if I’m stuck. You might not realize how uncommon that is unless you’ve spent a while being treated the other way.
Tags: work, ruby, rails, programming
Categories: programming · work
I finally managed to pick a weekend coding project that was actually weekend sized: I wrote a little program in Ruby to simulate bus passenger loads during rush hour. You can grab the code for it on my website. It’s just a rough draft, but it’s kind of fun to run a couple of times, changing the rates of people getting on and busses being added to the route.
I started this because I was thinking about how annoying it is that people living closer to downtown (like me) often have to watch a bus or two go by in the morning, before one with enough room finally stops. It seems like you could avoid this by either increasing the frequency of buses (though with the other traffic, anything more than the current ~7 minute spacing is likely to result in clumps of buses rather than a steady flow) or by adding an express bus every so often to pick up passengers from the more active stops. My model is still too simple to show any of this accurately, but if you add more than one person per stop per cycle, the people closest to the end of the route rarely find room on a bus.
Changes that would improve the simulation:
- Currently each bus moves down the route every cycle, and passengers are also added to stops at the same time. It would work in a more realistic manner if I made the cycles more like minutes, and used that to provide more flexibility to move each bus and add waiting passengers at different rates.
- The output is just four lines of text, representing the stops, people waiting, bus locations, and bus passengers. I could create a better graphical output for this.
- The only way to change any settings for the simulation is to alter the code. It would be pretty simple to ask the user for input before starting each time, or to read in parameters from a file.
- No one is getting off the bus. The rate of people leaving the bus in the last few miles to downtown is small, in my experience, but there are at least a few people getting off earlier most mornings, and I should include that.
Tags: ruby, programming, code, transit, bus, model, simulation
Categories: bus · code · model · programming · ruby · simulation · transit