File: iso-8859-1_steps.rb

package info (click to toggle)
cucumber 1.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,584 kB
  • sloc: ruby: 11,799; python: 28; makefile: 8; tcl: 3
file content (24 lines) | stat: -rw-r--r-- 773 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# encoding: iso-8859-1
# Ideally we would use Norwegian keywords here, but that won't work unless this file is UTF-8 encoded.
# Alternatively it would be possible to use Norwegian keywords and encode the file as UTF-8.
# 
# In both cases, stepdef arguments will be sent in as UTF-8, regardless of what encoding is used.
Given /^jeg drikker en "([^"]*)"$/ do |drink|
  drink.should == utf8('l', 'iso-8859-1')
end

When /^skal de andre si "([^"]*)"$/ do |greeting|
  greeting.should == utf8('skl', 'iso-8859-1')
end

module EncodingHelper
  def utf8(string, encoding)
    if string.respond_to?(:encode) # Ruby 1.9
      string.encode('UTF-8')
    else # Ruby 1.8
      require 'iconv'
      Iconv.new('UTF-8', encoding).iconv(string)
    end
  end
end
World(EncodingHelper)