require 'spec_helper' describe RegexpPreview::SingleLine do describe ".initialize" do subject { RegexpPreview::SingleLine.new("log_file.log", format, params) } describe "format" do let :params do { regexp: "(?\[.+\])", time_format: "%y/%m/%d", } end shared_examples "should set regexp and time_format from selected format" do it do expect(subject.regexp).to eq regexp expect(subject.time_format).to eq time_format expect(subject.params).to eq params end end shared_examples "should set params only" do include_examples "should set regexp and time_format from selected format" do let(:regexp) { nil } let(:time_format) { nil } end end context "regexp" do let(:format) { "regexp" } it 'should set regexp from params' do expect(subject.regexp).to eq /#{params[:regexp]}/ expect(subject.time_format).to be_nil expect(subject.params).to eq params end end context "ltsv" do let(:format) { "ltsv" } include_examples "should set params only" end context "json" do let(:format) { "json" } include_examples "should set params only" end context "csv" do let(:format) { "csv" } include_examples "should set params only" end context "tsv" do let(:format) { "tsv" } include_examples "should set params only" end context "syslog" do # "apache", "nginx", etc let(:format) { "syslog" } include_examples "should set regexp and time_format from selected format" do let(:regexp) do /^(?