Ever wonder how you can write a cucumber test that would test how your web app responds to a different format, something like JSON or XML?
I was trying to do the following:
Background: Given I am logged in And there is the following feeds: | title | body | category | | first feed | something good | default | | second feed | even better | notice | | 3rd feed | something awesome | notice | Scenario: Reading feeds via json When I go to the feeds page using json And I should see a json file And I should see 3 feeds in the json
Running this code I would get a “Can’t find mapping from “the feeds page using json” to a path.”
Trying to figure out how I can do this, I tried to write a new step, like this:
When %r{^I go to the (w+) page using (w+)$} do |page, format|...
but this resulted in: Ambiguous match of “I go to the feeds page using json”
So, I posted the question on StackOverFlow and it seems everyone was thinking the same way I was.
I continued playing with this idea and here is how I solved the problem:
Modifying the paths.rb file, I changed (Changes are in bold)
def path_to(page_name)
# Split out format if page_name includes ' using '
# Example: When I go to the accounts page using json
page_name, format = page_name.split(' using ')
case page_name
when /the homes?page/
'/'
when /the new account page/
#pass format
new_account_path(:format => format)
else
begin
page_name =~ /the (.*) page/
path_components = $1.split(/s+/)
# Also make sure to pass format to the 'guessed' path
self.send(path_components.push('path').join('_').to_sym, :format => format)
rescue Object => e
raise "Can't find mapping from "#{page_name}" to a path.n" +
"Now, go and add a mapping in #{__FILE__}"
end
end
end
end
This way I don’t have to modify anything else in my features and everything just works.
Learn MoreTrying to run:
sudo apachectl restart
Are you getting:
/usr/sbin/apachectl: line 82: ulimit: open files: cannot modify limit: Invalid argument
Edit your /usr/sbin/apachectl on line 65 from:
ULIMIT_MAX_FILES="ulimit -S -n `ulimit -H -n`"
to:
ULIMIT_MAX_FILES=""
and try again. It should now be working agian
For more information checkout Deversus
Learn MoreI’m happy to say that the blog is back!
Sorry for how long we were down but Anlek Consulting has moved offices and the local server (which was running this blog) was taken down and couldn’t be brought back up. So now we have a new home which should give us a better up time.
A little update on what’s going on at Anlek Consulting. I (Andrew) will be doing a trip around Canada and the USA, hoping to be working on the road with my cell phone and free wifi spots. In light of this, I’m going to probably blog a bit more about the challenges and adventures of working on the road. Stay tuned for some fun posts!
Learn MoreJust wanted to apologize for the very long break in our posts but I’ve been crazy busy with projects that I just haven’t had a moment to write about anything. But coming soon I will review the new SitePoint book ‘Everything You Know About CSS Is Wrong!‘.
So stay tuned, more stuff is coming!
Learn MoreWe just wanted to let everyone know that Anlek Consulting now has a blog!
We look forward to publishing the latest and greatest in the world of technology. Our main focus will be on Ruby on Rails, iPhone and Smarthomes. Of course we don’t want to limit our selfs to just those, so stay tune and see what we come up with!
Andrew
Learn More