Sha256: 649e8d08838888c7fd60b5d4b2dcbaf0324eb1161ba646a5b93e2acd29834edf
Contents?: true
Size: 1.75 KB
Versions: 3
Compression:
Stored size: 1.75 KB
Contents
# Author:: TAC (tac@tac42.net) require_relative 'spec_helper' ######## # Text # ######## describe 'Yasuri' do include_context 'httpserver' before do @agent = Mechanize.new @index_page = @agent.get(uri) end describe '::TextNode' do before { @node = Yasuri::TextNode.new('/html/body/p[1]', "title") } it 'scrape text text <p>Hello,Yasuri</p>' do actual = @node.inject(@agent, @index_page) expect(actual).to eq "Hello,Yasuri" end it 'return empty text if no match node' do no_match_node = Yasuri::TextNode.new('/html/body/no_match_node', "title") actual = no_match_node.inject(@agent, @index_page) expect(actual).to be_empty end it 'fail with invalid xpath' do invalid_xpath = '/html/body/no_match_node[' node = Yasuri::TextNode.new(invalid_xpath, "title") expect { node.inject(@agent, @index_page) }.to raise_error end it "can be defined by DSL, return single TextNode title" do generated = Yasuri.text_title '/html/body/p[1]' original = Yasuri::TextNode.new('/html/body/p[1]', "title") compare_generated_vs_original(generated, original, @index_page) end it "can be truncated with regexp" do node = Yasuri.text_title '/html/body/p[1]', /^[^,]+/ actual = node.inject(@agent, @index_page) expect(actual).to eq "Hello" end it "can be truncated with regexp" do node = Yasuri.text_title '/html/body/p[1]', /[^,]+$/ actual = node.inject(@agent, @index_page) expect(actual).to eq "Yasuri" end it "return empty string if truncated with no match to regexp" do node = Yasuri.text_title '/html/body/p[1]', /^hoge/ actual = node.inject(@agent, @index_page) expect(actual).to be_empty end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
yasuri-0.0.9 | spec/yasuri_text_node_spec.rb |
yasuri-0.0.8 | spec/yasuri_text_node_spec.rb |
yasuri-0.0.7 | spec/yasuri_text_node_spec.rb |