简体   繁体   中英

Rspec framework without cucumber and step definitions

There is need to build a rspec framework where in we don't want to write feature files and respective step definitions, to run our tests.

So far this is what I have tried this is test run, if it works I will write more.

my_example_spec.rb

require 'rspec'

describe 'Mybehaviour' do

  def testMethod
    visit(LoginPage).test
  end
end

login_page.rb

class LoginPage
 include PageObject

page_url("#{FigNewton.base_url}/login")

  element :username, "input[id='username']"
  element :password, "input[id='password']"
  element :submit, "input[id='submit']"

  def test
    puts "excellent"
  end

end 

I am using Rubymine when I right click my example file and run it , it gives me

Run options: include {:full_description=>/Mybehaviour/}

All examples were filtered out

0 examples, 0 failures, 0 passed

Finished in 0.000315 seconds

Process finished with exit code 0
Empty test suite.

So I changed it too:

require 'rspec'

describe 'Mybehaviour' do

  it 'test Method' do
    visit(LoginPage).test
    true.should == false
  end
end

it gives me:

Run options: include {:full_description=>/Mybehaviour/}

NameError: uninitialized constant LoginPage
./my_example_spec.rb:6:in `block (2 levels) in <top (required)>'
-e:1:in `load'
-e:1:in `<main>'

1 example, 1 failure, 0 passed

Finished in 0.001273 seconds

Process finished with exit code 1
  1. What is the difference when I was using def and when I used it ?
  2. I understand that I need to initialize LoginPage , but where and why it is calling it as constant LoginPage instead of class LoginPage .

PS:New to rspec

My guess is you need to require login_page.rb in your spec_helper.rb (if you have one), or at the top of my_example_spec.rb

The test doesn't know about the LoginPage class, and so when it hits visit(LoginPage).test on line 6 it thinks LoginPage is an undefined constant. It doesn't know that you have defined it as a class.

Try adding:

require 'login_page'

either in your spec_helper.rb or after require 'rspec' in my_example_spec.rb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM