dict 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. data/.gitignore +1 -1
  2. data/.rspec +2 -2
  3. data/.travis.yml +14 -14
  4. data/Gemfile +4 -4
  5. data/Gemfile.lock +40 -40
  6. data/README.md +34 -34
  7. data/Rakefile +8 -8
  8. data/bin/dict +7 -7
  9. data/dict.gemspec +28 -28
  10. data/lib/dict/cli/runner.rb +137 -115
  11. data/lib/dict/dict.rb +40 -53
  12. data/lib/dict/dictionary.rb +45 -62
  13. data/lib/dict/glosbe.rb +68 -66
  14. data/lib/dict/result.rb +38 -38
  15. data/lib/dict/version.rb +3 -3
  16. data/lib/dict/wiktionary.rb +91 -91
  17. data/lib/dict.rb +5 -5
  18. data/spec/dict/lib_dict_cli_runner_spec.rb +120 -120
  19. data/spec/dict/lib_dict_spec.rb +39 -39
  20. data/spec/dict/lib_glosbe_spec.rb +48 -34
  21. data/spec/dict/lib_wiktionary_spec.rb +68 -62
  22. data/spec/dict/spec_helper.rb +17 -17
  23. data/spec/dict/vcr_cassettes/glosbe_translations_asdfff_cassette.yml +1518 -0
  24. data/spec/dict/vcr_cassettes/glosbe_translations_atomic_cassette.yml +2794 -2794
  25. data/spec/dict/vcr_cassettes/glosbe_translations_usage_cassette.yml +2530 -0
  26. data/spec/dict/vcr_cassettes/glosbe_translations_woda_cassette.yml +1949 -1949
  27. data/spec/dict/vcr_cassettes/slowik_runner_cassette.yml +4178 -4178
  28. data/spec/dict/vcr_cassettes/translations_dragon_cassette.yml +8659 -8659
  29. data/spec/dict/vcr_cassettes/translations_slownik_cassette.yml +4177 -4177
  30. data/spec/dict/vcr_cassettes/wiktionary_no_usage_examples.yml +8634 -0
  31. data/spec/dict/vcr_cassettes/wiktionary_translate_result_uppercase.yml +6120 -0
  32. data/spec/dict/vcr_cassettes/wiktionary_translations_field_cassette.yml +8600 -8600
  33. data/spec/dict/vcr_cassettes/wiktionary_translations_samochod_cassette.yml +6140 -6140
  34. data/spec/dict/vcr_cassettes/wiktionary_usage_examples_kot.yml +6444 -0
  35. data/spec/dict/vcr_setup.rb +19 -19
  36. metadata +9 -4
@@ -1,120 +1,120 @@
1
- # -*- coding: utf-8 -*
2
-
3
- require_relative './vcr_setup'
4
- require 'dict/cli/runner'
5
- require 'slop'
6
-
7
- describe "parameters_valid?" do
8
- it "should return false if ARGV is empty" do
9
- stub_const("ARGV", [])
10
- runner = Dict::CLI::Runner.new
11
- runner.parameters_valid?.should == false
12
- end
13
-
14
- it "should return true if ARGV is not empty" do
15
- stub_const("ARGV", ["słowik", "-t", "36", "-d"])
16
- runner = Dict::CLI::Runner.new
17
- runner.parameters_valid?.should == true
18
- end
19
- end
20
-
21
- describe "parse_parameters" do
22
- it "should return Hash for parameters słowik -t 36" do
23
- stub_const("ARGV", ["słowik", "-t", "36"])
24
- runner = Dict::CLI::Runner.new
25
- opts = runner.parse_parameters
26
- {:help=>nil, :time=>"36", :dict=>nil, :version=>nil, :clean=>nil}.should == opts.to_hash
27
- end
28
-
29
- it "should return Hash for parameters słowik" do
30
- stub_const("ARGV", ["słowik"])
31
- runner = Dict::CLI::Runner.new
32
- opts = runner.parse_parameters
33
- {:help=>nil, :time=>nil, :dict=>nil, :version=>nil, :clean=>nil}.should == opts.to_hash
34
- end
35
- end
36
-
37
-
38
- describe "get_translations" do
39
- it "should return results from wiktionary and glosbe for word 'słowik'" do
40
- VCR.use_cassette('translations_slownik_cassette') do
41
- stub_const("ARGV", ["słowik"])
42
- runner = Dict::CLI::Runner.new
43
- opts = runner.parse_parameters
44
- runner.get_translations(opts, "słowik").should == {"wiktionary" => {"słowik" => ["nightingale"]}, "glosbe" => {"słowik" => ["nightingale", "bulbul"]}}
45
- end
46
- end
47
-
48
- it "should return results from selected dictionary for word 'słowik'" do
49
- VCR.use_cassette('translations_slownik_cassette') do
50
- stub_const("ARGV", ["słowik", "-d", "wiktionary"])
51
- runner = Dict::CLI::Runner.new
52
- opts = runner.parse_parameters
53
- runner.get_translations(opts, "słowik").should == {"słowik"=>["nightingale"]}
54
- end
55
- end
56
-
57
- it "should return timeout message for word słowik and -t 5" do
58
- stub_const("ARGV", ["słowik","-t","5"])
59
- runner = Dict::CLI::Runner.new
60
- opts = runner.parse_parameters
61
- Dict.should_receive(:get_all_dictionaries_translations).
62
- and_return { sleep 20 }
63
- runner.get_translations(opts, "słowik").should == "Timeout for the query."
64
- end
65
- end
66
-
67
- describe "CLI::Runner" do
68
- HELP_MSG = "Usage: dict WORD [OPTIONS]\nSearch WORD in dict, an open source dictionary aggregator.\n\n -h, --help Display this help message\n -t, --time Set timeout in seconds. Default: 300\n -d, --dict Select desired dictionary. Available options: wiktionary, glosbe\n -v, --version Information about gem, authors, license\n -c, --clean Remove examples from translation"
69
- DICT_MSG = "Missing argument. Expected: wiktionary, glosbe"
70
- TIME_MSG = "Missing argument. Expected: number of seconds"
71
- T_MSG = "Wrong time value."
72
-
73
- it "should call abort when program is called with -h" do
74
- stub_const("ARGV",["-h"])
75
- opts = Slop.new
76
- runner = Dict::CLI::Runner.new
77
- runner.should_receive(:abort).with(HELP_MSG).and_raise(SystemExit)
78
- expect {
79
- runner.run
80
- }.to raise_error(SystemExit)
81
- end
82
-
83
- it "should try to display meaningful information when -d option arguments are missing" do
84
- stub_const("ARGV",["-d"])
85
- runner = Dict::CLI::Runner.new
86
- runner.should_receive(:abort).with(DICT_MSG).and_raise(SystemExit)
87
- expect {
88
- runner.run
89
- }.to raise_error(SystemExit)
90
- end
91
-
92
- it "should try to display meaningful information when -t option arguments are missing" do
93
- stub_const("ARGV",["-t"])
94
- runner = Dict::CLI::Runner.new
95
- runner.should_receive(:abort).with(TIME_MSG).and_raise(SystemExit)
96
- expect {
97
- runner.run
98
- }.to raise_error(SystemExit)
99
- end
100
-
101
- it "should raise SystemExit and print msg when for parameter -t value is dupa" do
102
- stub_const("ARGV",["słowik", "-t","dupa"])
103
- runner = Dict::CLI::Runner.new
104
- runner.should_receive(:abort).with(T_MSG).and_raise(SystemExit)
105
- expect {
106
- runner.run
107
- }.to raise_error(SystemExit)
108
- end
109
-
110
- it "should return string when you use --clean parameter" do
111
- VCR.use_cassette('slowik_runner_cassette') do
112
- stub_const("ARGV",["słowik","--clean"])
113
- runner = Dict::CLI::Runner.new
114
- opts = runner.parse_parameters
115
- runner.clean_translation(opts, ARGV[0]).should == "słowik : nightingale, nightingale, bulbul"
116
- end
117
- end
118
-
119
-
120
- end
1
+ # -*- coding: utf-8 -*
2
+
3
+ require_relative './vcr_setup'
4
+ require 'dict/cli/runner'
5
+ require 'slop'
6
+
7
+ describe "parameters_valid?" do
8
+ it "should return false if ARGV is empty" do
9
+ stub_const("ARGV", [])
10
+ runner = Dict::CLI::Runner.new
11
+ runner.parameters_valid?.should == false
12
+ end
13
+
14
+ it "should return true if ARGV is not empty" do
15
+ stub_const("ARGV", ["słowik", "-t", "36", "-d"])
16
+ runner = Dict::CLI::Runner.new
17
+ runner.parameters_valid?.should == true
18
+ end
19
+ end
20
+
21
+ describe "parse_parameters" do
22
+ it "should return Hash for parameters słowik -t 36" do
23
+ stub_const("ARGV", ["słowik", "-t", "36"])
24
+ runner = Dict::CLI::Runner.new
25
+ opts = runner.parse_parameters
26
+ {:help=>nil, :time=>"36", :dict=>nil, :version=>nil, :clean=>nil}.should == opts.to_hash
27
+ end
28
+
29
+ it "should return Hash for parameters słowik" do
30
+ stub_const("ARGV", ["słowik"])
31
+ runner = Dict::CLI::Runner.new
32
+ opts = runner.parse_parameters
33
+ {:help=>nil, :time=>nil, :dict=>nil, :version=>nil, :clean=>nil}.should == opts.to_hash
34
+ end
35
+ end
36
+
37
+
38
+ describe "get_translations" do
39
+ it "should return results from wiktionary and glosbe for word 'słowik'" do
40
+ VCR.use_cassette('translations_slownik_cassette') do
41
+ stub_const("ARGV", ["słowik"])
42
+ runner = Dict::CLI::Runner.new
43
+ opts = runner.parse_parameters
44
+ runner.get_translations(opts, "słowik").should == {"wiktionary" => {"słowik" => ["nightingale"]}, "glosbe" => {"słowik" => ["nightingale", "bulbul"]}}
45
+ end
46
+ end
47
+
48
+ it "should return results from selected dictionary for word 'słowik'" do
49
+ VCR.use_cassette('translations_slownik_cassette') do
50
+ stub_const("ARGV", ["słowik", "-d", "wiktionary"])
51
+ runner = Dict::CLI::Runner.new
52
+ opts = runner.parse_parameters
53
+ runner.get_translations(opts, "słowik").should == {"słowik"=>["nightingale"]}
54
+ end
55
+ end
56
+
57
+ it "should return timeout message for word słowik and -t 5" do
58
+ stub_const("ARGV", ["słowik","-t","5"])
59
+ runner = Dict::CLI::Runner.new
60
+ opts = runner.parse_parameters
61
+ Dict.should_receive(:get_all_dictionaries_translations).
62
+ and_return { sleep 20 }
63
+ runner.get_translations(opts, "słowik").should == "Upłynął limit czasu żądania."
64
+ end
65
+ end
66
+
67
+ describe "CLI::Runner" do
68
+ HELP_MSG = "Przykład użycia: dict SŁOWO [OPCJE]\nWyszukaj SŁOWO w dict, open-source'owym agregatorze słowników. \n\n -h, --help Wyświetl pomoc\n -t, --time Ustaw limit czasu żądania w sekundach. Domyślnie: 300\n -d, --dict Wybierz słownik. Dostępne : wiktionary, glosbe\n -v, --version Informacje o gemie, autorach, licencji\n -c, --clean Nie wyświetlaj przykładów użycia"
69
+ DICT_MSG = "Brakujący argument. Spodziewano: wiktionary, glosbe"
70
+ TIME_MSG = "Brakujący argument. Spodziewano: liczba sekund"
71
+ T_MSG = "Nieprawidłowa wartość czasu."
72
+
73
+ it "should call abort when program is called with -h" do
74
+ stub_const("ARGV",["-h"])
75
+ opts = Slop.new
76
+ runner = Dict::CLI::Runner.new
77
+ runner.should_receive(:abort).with(HELP_MSG).and_raise(SystemExit)
78
+ expect {
79
+ runner.run
80
+ }.to raise_error(SystemExit)
81
+ end
82
+
83
+ it "should try to display meaningful information when -d option arguments are missing" do
84
+ stub_const("ARGV",["-d"])
85
+ runner = Dict::CLI::Runner.new
86
+ runner.should_receive(:abort).with(DICT_MSG).and_raise(SystemExit)
87
+ expect {
88
+ runner.run
89
+ }.to raise_error(SystemExit)
90
+ end
91
+
92
+ it "should try to display meaningful information when -t option arguments are missing" do
93
+ stub_const("ARGV",["-t"])
94
+ runner = Dict::CLI::Runner.new
95
+ runner.should_receive(:abort).with(TIME_MSG).and_raise(SystemExit)
96
+ expect {
97
+ runner.run
98
+ }.to raise_error(SystemExit)
99
+ end
100
+
101
+ it "should raise SystemExit and print msg when for parameter -t value is dupa" do
102
+ stub_const("ARGV",["słowik", "-t","dupa"])
103
+ runner = Dict::CLI::Runner.new
104
+ runner.should_receive(:abort).with(T_MSG).and_raise(SystemExit)
105
+ expect {
106
+ runner.run
107
+ }.to raise_error(SystemExit)
108
+ end
109
+
110
+ it "should return array without duplicates when you use --clean parameter" do
111
+ VCR.use_cassette('slowik_runner_cassette') do
112
+ stub_const("ARGV",["słowik","--clean"])
113
+ runner = Dict::CLI::Runner.new
114
+ opts = runner.parse_parameters
115
+ runner.clean_translation(runner.get_translations(opts, ARGV[0])).should == ["nightingale", "bulbul"]
116
+ end
117
+ end
118
+
119
+
120
+ end
@@ -1,39 +1,39 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'dict/dict'
4
-
5
- describe Dict do
6
-
7
- it "should return array of available services which is not empty" do
8
- arr = Dict.available_dictionaries
9
- arr.should be_a(Array)
10
- arr.size.should_not == 0
11
- end
12
-
13
- it "should return array of available services, which contains wiktionary and glosbe" do
14
- Dict.available_dictionaries.should == ['wiktionary', 'glosbe']
15
- end
16
-
17
- it "should return hash with translations from all dictionaries" do
18
- wiktionary = stub(:translate => stub(:translations => {'WORD' => 'WIKTIONARY_RESULTS'}))
19
- Dict::Wiktionary.should_receive(:new).with('WORD').and_return(wiktionary)
20
-
21
- glosbe = stub(:translate => stub(:translations => {'WORD' => 'GLOSBE_RESULTS'}))
22
- Dict::Glosbe.should_receive(:new).with('WORD').and_return(glosbe)
23
-
24
- results = Dict::get_all_dictionaries_translations('WORD')
25
- results.should == {'wiktionary' => {'WORD' => 'WIKTIONARY_RESULTS'}, 'glosbe' => {'WORD' => 'GLOSBE_RESULTS'}}
26
- end
27
-
28
- it "should return whatever Wiktionary returns embedded in a hash" do
29
- wiktionary = stub(:translate => stub( :translations => 'WIKTIONARY_RESULTS'))
30
- Dict::Wiktionary.should_receive(:new).with('WORD').and_return(wiktionary)
31
- Dict.get_single_dictionary_translations('WORD', 'wiktionary').should == 'WIKTIONARY_RESULTS'
32
- end
33
-
34
- it "should return whatever Glosbe returns embedded in a hash" do
35
- glosbe = stub(:translate => stub( :translations => 'GLOSBE_RESULTS'))
36
- Dict::Glosbe.should_receive(:new).with('WORD').and_return(glosbe)
37
- Dict.get_single_dictionary_translations('WORD', 'glosbe').should == 'GLOSBE_RESULTS'
38
- end
39
- end
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'dict/dict'
4
+
5
+ describe Dict do
6
+
7
+ it "should return array of available services which is not empty" do
8
+ arr = Dict.available_dictionaries
9
+ arr.should be_a(Array)
10
+ arr.size.should_not == 0
11
+ end
12
+
13
+ it "should return array of available services, which contains wiktionary and glosbe" do
14
+ Dict.available_dictionaries.should == ['wiktionary', 'glosbe']
15
+ end
16
+
17
+ it "should return hash with translations from all dictionaries" do
18
+ wiktionary = stub(:translate => stub(:translations => {'WORD' => 'WIKTIONARY_RESULTS'}))
19
+ Dict::Wiktionary.should_receive(:new).with('WORD').and_return(wiktionary)
20
+
21
+ glosbe = stub(:translate => stub(:translations => {'WORD' => 'GLOSBE_RESULTS'}))
22
+ Dict::Glosbe.should_receive(:new).with('WORD').and_return(glosbe)
23
+
24
+ results = Dict::get_all_dictionaries_translations('WORD')
25
+ results.should == {'wiktionary' => {'WORD' => 'WIKTIONARY_RESULTS'}, 'glosbe' => {'WORD' => 'GLOSBE_RESULTS'}}
26
+ end
27
+
28
+ it "should return whatever Wiktionary returns embedded in a hash" do
29
+ wiktionary = stub(:translate => stub( :translations => 'WIKTIONARY_RESULTS'))
30
+ Dict::Wiktionary.should_receive(:new).with('WORD').and_return(wiktionary)
31
+ Dict.get_single_dictionary_translations('WORD', 'wiktionary').should == 'WIKTIONARY_RESULTS'
32
+ end
33
+
34
+ it "should return whatever Glosbe returns embedded in a hash" do
35
+ glosbe = stub(:translate => stub( :translations => 'GLOSBE_RESULTS'))
36
+ Dict::Glosbe.should_receive(:new).with('WORD').and_return(glosbe)
37
+ Dict.get_single_dictionary_translations('WORD', 'glosbe').should == 'GLOSBE_RESULTS'
38
+ end
39
+ end
@@ -1,34 +1,48 @@
1
- # -*- encoding: utf-8 -*
2
-
3
- require_relative './vcr_setup'
4
- require 'dict/glosbe'
5
-
6
- describe Dict::Glosbe do
7
-
8
- it "should raise no given word exception" do
9
- expect { Dict::Glosbe.new }.to raise_error ArgumentError
10
- end
11
-
12
- it "should return a Result object" do
13
- VCR.use_cassette('glosbe_translations_woda_cassette') do
14
- g = Dict::Glosbe.new('woda').translate
15
- g.should be_a(Dict::Result)
16
- end
17
- end
18
-
19
- it "should return translations of polish word 'woda' to english with its examples" do
20
- VCR.use_cassette('glosbe_translations_woda_cassette') do
21
- g = Dict::Glosbe.new('woda').translate
22
- g.translations.should == {"woda"=>["water", "aqua"]}
23
- g.examples.should == {"woda"=>["Details of food and water quality", "Mineral waters, soft drinks and juices (nd", "Fishing for herring in area iia (ec waters", "Bind him, cast him into the slop- pool at low tide!"]}
24
- end
25
- end
26
-
27
- it "should return translations of english word 'atomic' to polish with its examples" do
28
- VCR.use_cassette('glosbe_translations_atomic_cassette') do
29
- g = Dict::Glosbe.new('atomic').translate
30
- g.translations.should == {"atomic"=>["atomowy", "niepodzielny", "atomistyczny", "jednolity"]}
31
- g.examples.should == {"atomic"=>["Spektrofotometr absorpcji atomowej", "Atom w lewo", "Pomiary metodą absorpcji atomowej"]}
32
- end
33
- end
34
- end
1
+ # -*- encoding: utf-8 -*
2
+
3
+ require_relative './vcr_setup'
4
+ require 'dict/glosbe'
5
+
6
+ describe Dict::Glosbe do
7
+
8
+ it "should raise no given word exception" do
9
+ expect { Dict::Glosbe.new }.to raise_error ArgumentError
10
+ end
11
+
12
+ it "should return a Result object" do
13
+ VCR.use_cassette('glosbe_translations_woda_cassette') do
14
+ g = Dict::Glosbe.new('woda').translate
15
+ g.should be_a(Dict::Result)
16
+ end
17
+ end
18
+
19
+ it "should return empty hash with translations for word asdfff" do
20
+ VCR.use_cassette('glosbe_translations_asdfff_cassette') do
21
+ g = Dict::Glosbe.new('asdfff').translate
22
+ g.translations.should eq({})
23
+ end
24
+ end
25
+
26
+ it "should return translations of polish word 'woda' to english with its examples" do
27
+ VCR.use_cassette('glosbe_translations_woda_cassette') do
28
+ g = Dict::Glosbe.new('woda').translate
29
+ g.translations.should == {"woda"=>["water", "aqua"]}
30
+ g.examples.should == {"woda"=>["Details of food and water quality", "Mineral waters, soft drinks and juices (nd", "Fishing for herring in area iia (ec waters", "Bind him, cast him into the slop- pool at low tide!"]}
31
+ end
32
+ end
33
+
34
+ it "should return translations of english word 'atomic' to polish with its examples" do
35
+ VCR.use_cassette('glosbe_translations_atomic_cassette') do
36
+ g = Dict::Glosbe.new('atomic').translate
37
+ g.translations.should == {"atomic"=>["atomowy", "niepodzielny", "atomistyczny", "jednolity"]}
38
+ g.examples.should == {"atomic"=>["Spektrofotometr absorpcji atomowej", "Atom w lewo", "Pomiary metodą absorpcji atomowej"]}
39
+ end
40
+ end
41
+
42
+ it "should return translations results for english word 'usage'" do
43
+ VCR.use_cassette('glosbe_translations_usage_cassette') do
44
+ g = Dict::Glosbe.new('usage').translate
45
+ g.translations.should == {"usage"=>["użycie", "obchodzenie", "stosowanie", "stosować", "tradycje", "traktowanie", "użytkowanie", "używać", "zastosowanie", "zużycie", "zwyczaj", "zwyczaje"]}
46
+ end
47
+ end
48
+ end
@@ -1,62 +1,68 @@
1
- # -*- encoding: utf-8 -*
2
-
3
- require_relative './vcr_setup'
4
- require 'dict/wiktionary'
5
-
6
- describe Dict::Wiktionary do
7
-
8
- it "should raise no given word exception" do
9
- expect { Dict::Wiktionary.new }.to raise_error ArgumentError
10
- end
11
-
12
- it "should return an two element array of translations of word samochód containing [\"car\",\"automobile\"]" do
13
- VCR.use_cassette('wiktionary_translations_samochod_cassette') do
14
- w = Dict::Wiktionary.new("samochód").translate
15
- w.translations.should == {"samochód"=>["car", "automobile"]}
16
- end
17
- end
18
-
19
- it "should return a hash with translations" do
20
- VCR.use_cassette('wiktionary_translations_samochod_cassette') do
21
- w = Dict::Wiktionary.new("samochód").translate
22
- w.translations.should be_a(Hash)
23
- end
24
- end
25
-
26
- it "should return a Result object" do
27
- VCR.use_cassette('wiktionary_translations_samochod_cassette') do
28
- w = Dict::Wiktionary.new("samochód").translate
29
- w.should be_a(Dict::Result)
30
- end
31
- end
32
-
33
- it "should return translation from english to polish for word 'field'" do
34
- VCR.use_cassette('wiktionary_translations_field_cassette') do
35
- w = Dict::Wiktionary.new("field").translate.translations
36
- w.should eq({"field"=>["pole", "pole (magnetyczne, elektryczne, sił, itp.)", "pole (skalarne, wektorowe, itp.)", "ciało (liczb rzeczywistych, zespolonych, itp.)", "wystawić (drużynę)", "odpowiadać (na pytania)", "polowy", "polny"]})
37
- end
38
- end
39
-
40
- it "should remove html tags from translations of 'dragon' word" do
41
- VCR.use_cassette('translations_dragon_cassette') do
42
- Dict::Wiktionary.new("dragon").translate.translations.should eq({'dragon' => ['smok']})
43
- end
44
- end
45
-
46
- it "should return translations for word written with uppercase letters" do
47
- result = Dict::Wiktionary.new('SaMoCHÓd').translate.translations
48
- result.should eq({"samochód"=>["car", "automobile"]})
49
- end
50
-
51
- describe "#examples" do
52
- it "should return a empty hash of usage examples to 'assdd' word" do
53
- result = Dict::Wiktionary.new('field').translate.examples
54
- result.should eq({})
55
- end
56
-
57
- it "should return a hash containing usage examples to 'kot' word" do
58
- result = Dict::Wiktionary.new('kot').translate.examples
59
- result.should eq({"cat" => ["No room to swing a cat."]})
60
- end
61
- end
62
- end
1
+ # -*- encoding: utf-8 -*
2
+
3
+ require_relative './vcr_setup'
4
+ require 'dict/wiktionary'
5
+
6
+ describe Dict::Wiktionary do
7
+
8
+ it "should raise no given word exception" do
9
+ expect { Dict::Wiktionary.new }.to raise_error ArgumentError
10
+ end
11
+
12
+ it "should return an two element array of translations of word samochód containing [\"car\",\"automobile\"]" do
13
+ VCR.use_cassette('wiktionary_translations_samochod_cassette') do
14
+ w = Dict::Wiktionary.new("samochód").translate
15
+ w.translations.should == {"samochód"=>["car", "automobile"]}
16
+ end
17
+ end
18
+
19
+ it "should return a hash with translations" do
20
+ VCR.use_cassette('wiktionary_translations_samochod_cassette') do
21
+ w = Dict::Wiktionary.new("samochód").translate
22
+ w.translations.should be_a(Hash)
23
+ end
24
+ end
25
+
26
+ it "should return a Result object" do
27
+ VCR.use_cassette('wiktionary_translations_samochod_cassette') do
28
+ w = Dict::Wiktionary.new("samochód").translate
29
+ w.should be_a(Dict::Result)
30
+ end
31
+ end
32
+
33
+ it "should return translation from english to polish for word 'field'" do
34
+ VCR.use_cassette('wiktionary_translations_field_cassette') do
35
+ w = Dict::Wiktionary.new("field").translate.translations
36
+ w.should eq({"field"=>["pole", "pole (magnetyczne, elektryczne, sił, itp.)", "pole (skalarne, wektorowe, itp.)", "ciało (liczb rzeczywistych, zespolonych, itp.)", "wystawić (drużynę)", "odpowiadać (na pytania)", "polowy", "polny"]})
37
+ end
38
+ end
39
+
40
+ it "should remove html tags from translations of 'dragon' word" do
41
+ VCR.use_cassette('translations_dragon_cassette') do
42
+ Dict::Wiktionary.new("dragon").translate.translations.should eq({'dragon' => ['smok']})
43
+ end
44
+ end
45
+
46
+ it "should return translations for word written with uppercase letters" do
47
+ VCR.use_cassette('wiktionary_translate_result_uppercase') do
48
+ result = Dict::Wiktionary.new('SaMoCHÓd').translate.translations
49
+ result.should eq({"samochód"=>["car", "automobile"]})
50
+ end
51
+ end
52
+
53
+ describe "#examples" do
54
+ it "should return a empty hash of usage examples to 'assdd' word" do
55
+ VCR.use_cassette('wiktionary_no_usage_examples') do
56
+ result = Dict::Wiktionary.new('field').translate.examples
57
+ result.should eq({})
58
+ end
59
+ end
60
+
61
+ it "should return a hash containing usage examples to 'kot' word" do
62
+ VCR.use_cassette('wiktionary_usage_examples_kot') do
63
+ result = Dict::Wiktionary.new('kot').translate.examples
64
+ result.should eq({"cat" => ["No room to swing a cat."]})
65
+ end
66
+ end
67
+ end
68
+ end
@@ -1,17 +1,17 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # Require this file using `require "spec_helper"` to ensure that it is only
4
- # loaded once.
5
- #
6
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
- RSpec.configure do |config|
8
- config.treat_symbols_as_metadata_keys_with_true_values = true
9
- config.run_all_when_everything_filtered = true
10
- config.filter_run :focus
11
-
12
- # Run specs in random order to surface order dependencies. If you find an
13
- # order dependency and want to debug it, you can fix the order by providing
14
- # the seed, which is printed after each run.
15
- # --seed 1234
16
- config.order = 'random'
17
- end
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end